Python 2.7 如何获取Python';s os.system()来运行Windows 10 tftp客户端功能?

Python 2.7 如何获取Python';s os.system()来运行Windows 10 tftp客户端功能?,python-2.7,windows-10,tftp,Python 2.7,Windows 10,Tftp,在Windows10上使用Python 2.7。我想使用Windows tftp客户端。为什么os.system()会给出与在命令提示符下键入tftp命令不同的结果?(使用2.7而不是3,Windows TFTP客户端而不是寻找另一个库,“因为老板这么说”。) 我不知道这是一个Python问题,一个Windows10问题,还是Windows10TFTP客户端的问题 TFTP客户端已安装在我的计算机上。如果打开命令shell并键入tftp,则会从tftp客户端收到一条帮助消息 >tftp

在Windows10上使用Python 2.7。我想使用Windows tftp客户端。为什么os.system()会给出与在命令提示符下键入tftp命令不同的结果?(使用2.7而不是3,Windows TFTP客户端而不是寻找另一个库,“因为老板这么说”。)

我不知道这是一个Python问题,一个Windows10问题,还是Windows10TFTP客户端的问题

TFTP客户端已安装在我的计算机上。如果打开命令shell并键入tftp,则会从tftp客户端收到一条帮助消息

>tftp

Transfers files to and from a remote computer running the TFTP service.

TFTP [-i] host [GET | PUT] source [destination]
...
但是如果我从Python尝试,则找不到tftp客户端:

>python
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.system('tftp')
'tftp' is not recognized as an internal or external command,
operable program or batch file.
1
>>>
有一个C:\Windows\system32\TFTP.EXE,C:\Windows\system32在我的路径上。如果我尝试使用C:\Windows\system32中的其他exe文件,例如tar.exe,它可以工作:

>>> os.system('tar')
tar: Must specify one of -c, -r, -t, -u, -x
1
在我的机器上有一个“which”实用程序,它也没有找到tftp的.exe文件,但它确实找到了tar,这让我很困惑。我注意到TFTP.EXE的扩展名是大写的,而tar.EXE的扩展名是小写的,但据我所知,Windows从来都不区分大小写,而且无论如何,我尝试了大写和小写两种命令

另外,我认为os.system()只是将字符串传递给系统执行。因此,如果在shell提示符下键入的相同命令起作用,Windows肯定会找到该实用程序吗


我还尝试了os.system(“cmd/c tftp”),得到了相同的结果——如果我在命令提示符下键入它,而不是从os.system()键入它,它就会工作。在tftp周围加引号或添加显式.exe(或.exe)也不起作用

在Windows 10中,要从Python运行tftp.exe,我必须运行C:\Windows\SysNative\tftp.exe

>>> os.system("c:\\windows\\system32\\tftp")
'c:\windows\system32\tftp' is not recognized as an internal or external command,
operable program or batch file.
1
>>> os.system("c:\\windows\\sysnative\\tftp")

Transfers files to and from a remote computer running the TFTP service.
...
存在C:\windows\system32\tftp.exe,但此计算机上没有C:\windows\sysnative\tftp.exe。事实上,没有sysnative目录,甚至从以管理员身份启动的shell中查找系统和隐藏文件。所以我不明白这一点。但它是有效的

对我来说,这似乎是微软不得不真正阻止使用tftp.exe的黑客行为,所以也许我应该接受这个暗示