Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“我怎么跑?”;windows功能“;通过Python?_Python_Windows_Command Line - Fatal编程技术网

“我怎么跑?”;windows功能“;通过Python?

“我怎么跑?”;windows功能“;通过Python?,python,windows,command-line,Python,Windows,Command Line,我正在尝试从python脚本运行tftp。我将其作为Windows 10功能()启用,因此可以通过命令行运行它。但当我试图通过python运行它时,我会出错。我尝试了3种调用它的方法:os.system、subprocess.call、subprocess.Popen,作为一个“控件”,我使用这些子进程成功地调用了“dir”。我还尝试从完整路径调用tftp。代码和输出粘贴在下面。我添加了延迟和一些打印来帮助解析 我的猜测是,在使用这些方法时,我启用的其他“windows功能”并不是Python看

我正在尝试从python脚本运行
tftp
。我将其作为Windows 10功能()启用,因此可以通过命令行运行它。但当我试图通过python运行它时,我会出错。我尝试了3种调用它的方法:os.system、subprocess.call、subprocess.Popen,作为一个“控件”,我使用这些子进程成功地调用了“dir”。我还尝试从完整路径调用tftp。代码和输出粘贴在下面。我添加了延迟和一些打印来帮助解析

我的猜测是,在使用这些方法时,我启用的其他“windows功能”并不是Python看到的环境的一部分。但是我不确定如何指定包含该功能的环境

call("dir", shell = True)
print "*******************************************"
time.sleep(1)
call("tftp", shell = True)
print "*******************************************"
time.sleep(1)
call("C:\Windows\System32\\tftp.exe", shell = True)
print "*******************************************"
time.sleep(1)
Popen("dir", shell = True)
print "*******************************************"
time.sleep(1)
Popen("tftp", shell = True)
print "*******************************************"
time.sleep(1)
Popen("C:\Windows\System32\\tftp.exe", shell = True)
print "*******************************************"
time.sleep(1)
os.system("dir")
print "*******************************************"
time.sleep(1)
os.system("tftp")
print "*******************************************"
time.sleep(1)
os.system("C:\Windows\System32\\tftp.exe")
print "*******************************************"
time.sleep(1)
我得到的结果是:

Directory of C:\[REDACTED]

07/26/2016  11:05 AM    <DIR>          .
07/26/2016  11:05 AM    <DIR>          ..
07/26/2016  11:05 AM             1,724 [REDACTED].py
07/26/2016  11:05 AM             1,828 [REDACTED].pyc
07/23/2016  05:36 PM             1,933 prep_for_bootload.py
07/26/2016  07:52 AM                13 s.bat
07/26/2016  11:19 AM             1,449 scrap.py
07/26/2016  10:38 AM               672 test_script.py
07/26/2016  10:39 AM                90 upload_script.bat
               7 File(s)          7,709 bytes
               2 Dir(s)  222,286,884,864 bytes free
*******************************************
'tftp' is not recognized as an internal or external command,
operable program or batch file.
*******************************************
'C:\Windows\System32\tftp.exe' is not recognized as an internal or external command,
operable program or batch file.
*******************************************
*******************************************
 Volume in drive C has no label.
 Volume Serial Number is 2AC7-8D0E

 Directory of C:\Users\[REDACTED]

07/26/2016  11:05 AM    <DIR>          .
07/26/2016  11:05 AM    <DIR>          ..
07/26/2016  11:05 AM             1,724 [REDACTED]
07/26/2016  11:05 AM             1,828 [REDACTED]
07/23/2016  05:36 PM             1,933 prep_for_bootload.py
07/26/2016  07:52 AM                13 s.bat
07/26/2016  11:19 AM             1,449 scrap.py
07/26/2016  10:38 AM               672 test_script.py
07/26/2016  10:39 AM                90 upload_script.bat
               7 File(s)          7,709 bytes
               2 Dir(s)  222,286,884,864 bytes free
*******************************************
'tftp' is not recognized as an internal or external command,
operable program or batch file.
*******************************************
'C:\Windows\System32\tftp.exe' is not recognized as an internal or external command,
operable program or batch file.
 Volume in drive C has no label.
 Volume Serial Number is 2AC7-8D0E

 Directory of C:\Users\[REDACTED]

07/26/2016  11:05 AM    <DIR>          .
07/26/2016  11:05 AM    <DIR>          ..
07/26/2016  11:05 AM             1,724 [REDACTED]
07/26/2016  11:05 AM             1,828 [REDACTED]
07/23/2016  05:36 PM             1,933 prep_for_bootload.py
07/26/2016  07:52 AM                13 s.bat
07/26/2016  11:19 AM             1,449 scrap.py
07/26/2016  10:38 AM               672 test_script.py
07/26/2016  10:39 AM                90 upload_script.bat
               7 File(s)          7,709 bytes
               2 Dir(s)  222,286,884,864 bytes free
*******************************************
'tftp' is not recognized as an internal or external command,
operable program or batch file.
*******************************************
'C:\Windows\System32\tftp.exe' is not recognized as an internal or external command,
operable program or batch file.
*******************************************
C:\[修订版]目录 2016年7月26日上午11:05。 2016年7月26日上午11:05。。 2016年7月26日上午11:05 1724[修订版].py 2016年7月26日上午11:05(1828)[修订版].pyc 2016年7月23日下午5时36分1933准备启动.py 2016年7月26日上午7:52南蝙蝠岛13号 2016年7月26日上午11:19 1449.py 2016年7月26日上午10:38 672测试脚本 2016年7月26日上午10:39 90上传脚本.bat 7个文件7709字节 2个目录222286884864个可用字节 ******************************************* “tftp”未被识别为内部或外部命令, 可操作的程序或批处理文件。 ******************************************* “C:\Windows\System32\tftp.exe”未被识别为内部或外部命令, 可操作的程序或批处理文件。 ******************************************* ******************************************* 驱动器C中的卷没有标签。 卷序列号为2AC7-8D0E C:\Users\[修订版]目录 2016年7月26日上午11:05。 2016年7月26日上午11:05。。 2016年7月26日上午11:05 1724[修订] 2016年7月26日上午11:05 1828[修订] 2016年7月23日下午5时36分1933准备启动.py 2016年7月26日上午7:52南蝙蝠岛13号 2016年7月26日上午11:19 1449.py 2016年7月26日上午10:38 672测试脚本 2016年7月26日上午10:39 90上传脚本.bat 7个文件7709字节 2个目录222286884864个可用字节 ******************************************* “tftp”未被识别为内部或外部命令, 可操作的程序或批处理文件。 ******************************************* “C:\Windows\System32\tftp.exe”未被识别为内部或外部命令, 可操作的程序或批处理文件。 驱动器C中的卷没有标签。 卷序列号为2AC7-8D0E C:\Users\[修订版]目录 2016年7月26日上午11:05。 2016年7月26日上午11:05。。 2016年7月26日上午11:05 1724[修订] 2016年7月26日上午11:05 1828[修订] 2016年7月23日下午5时36分1933准备启动.py 2016年7月26日上午7:52南蝙蝠岛13号 2016年7月26日上午11:19 1449.py 2016年7月26日上午10:38 672测试脚本 2016年7月26日上午10:39 90上传脚本.bat 7个文件7709字节 2个目录222286884864个可用字节 ******************************************* “tftp”未被识别为内部或外部命令, 可操作的程序或批处理文件。 ******************************************* “C:\Windows\System32\tftp.exe”未被识别为内部或外部命令, 可操作的程序或批处理文件。 *******************************************
有关正确答案,请参阅@eryksun的回复。引述如下:


“要在这两种情况下工作,请使用system32='SysNative'if platform.architecture()[0]='32bit'或'system32'。然后将完全限定路径创建为tftp_path=os.path.join(os.environ['SystemRoot'],system32,'tftp.EXE')”

您是否尝试过定位
tftp
命令所在的位置,并从其完整位置手动调用它?也就是说,如果它安装在
c:\windows\tftp.exe
,请使用完整路径从python调用它。是的,我也尝试过——将它添加到我的OP
“\t”
是一个制表符,而不是后跟“t”的反斜杠。最好使用本机实现,而不是分叉。它将提供更好的集成和更好的错误处理。请参阅。请提供您使用的确切代码。你可以用自己的话写一个答案。这是一个非常常见的问题,但我不认为很容易找到答案,因为在您尝试执行的操作(执行程序)和底层问题(WOW64下的文件系统虚拟化)之间存在根本性的脱节。