Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.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
Python找不到某些windows可执行文件_Python_Windows Subsystem For Linux - Fatal编程技术网

Python找不到某些windows可执行文件

Python找不到某些windows可执行文件,python,windows-subsystem-for-linux,Python,Windows Subsystem For Linux,我似乎无法在windows上用python运行某些特定的可执行文件。 在运行这些可执行文件时,我得到一个“未找到文件”错误 我可以使用多种方法运行其他可执行文件,如winver.exe: subprocess.Popen( [r"C:\Windows\System32\winver.exe"] ) subprocess.run( [r"C:\Windows\System32\winver.exe"] ) subprocess.run( ["winver"] ) subprocess.Popen(

我似乎无法在windows上用python运行某些特定的可执行文件。 在运行这些可执行文件时,我得到一个“未找到文件”错误

我可以使用多种方法运行其他可执行文件,如winver.exe:

subprocess.Popen( [r"C:\Windows\System32\winver.exe"] )
subprocess.run( [r"C:\Windows\System32\winver.exe"] )
subprocess.run( ["winver"] )
subprocess.Popen( ["winver"] )
os.system( "winver" )
但我似乎无法让wsl、bash、ssh或sftp正常工作:

subprocess.Popen( [r"C:\Windows\System32\wsl.exe"] )
subprocess.run( [r"C:\Windows\System32\wsl.exe"] )
subprocess.run( ["wsl"] )
subprocess.Popen( ["wsl"] )
os.system( "wsl" )

subprocess.Popen( [r"C:\Windows\System32\bash.exe"] )
subprocess.run( [r"C:\Windows\System32\bash.exe"] )
subprocess.run( ["bash"] )
subprocess.Popen( ["bash"] )
os.system( "bash" )

subprocess.Popen( [r"C:\Windows\System32\OpenSSH\ssh.exe"] )
subprocess.run( [r"C:\Windows\System32\OpenSSH\ssh.exe"] )
subprocess.run( ["ssh"] )
subprocess.Popen( ["ssh"] )
os.system( "ssh" )

subprocess.Popen( [r"C:\Windows\System32\OpenSSH\sftp.exe"] )
subprocess.run( [r"C:\Windows\System32\OpenSSH\sftp.exe"] )
subprocess.run( ["sftp"] )
subprocess.Popen( ["sftp"] )
os.system( "sftp" )
sftp的错误:

  File "d:/Griffin/Documents/Coding/Python/network.py", line 42, in <module>
    val = subprocess.Popen( [r"C:\Windows\System32\OpenSSH\sftp.exe"] )
  File "C:\Users\Griffin\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "C:\Users\Griffin\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1178, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

Traceback (most recent call last):
  File "d:/Griffin/Documents/Coding/Python/network.py", line 44, in <module>
    val = subprocess.run( ["sftp"] )
  File "C:\Users\Griffin\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 472, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\Griffin\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "C:\Users\Griffin\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1178, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

'sftp' is not recognized as an internal or external command,
operable program or batch file.
Traceback (most recent call last):
  File "d:/Griffin/Documents/Coding/Python/network.py", line 48, in <module>
    os.chdir( "C:\Windows\System32\OpenSSH" )
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Windows\\System32\\OpenSSH'
如果我在OpenSSH目录上尝试相同的方法,则不会完全找到它

os.chdir( "C:\Windows\System32\OpenSSH" )
val = os.system( "dir" )

print( val )

正如您所期望的,所有这些在python之外都可以很好地工作,而且它们也可以从.bat开始工作

你能把stacktrace贴出来吗?注意,chdir的参数也忽略了原始前缀。请发布同样有效的.bat文件。.bat文件只包含一行程序名(ssh/sftp/winver)。您可以发布stacktrace吗?注意,chdir的参数也忽略了原始前缀。请发布同样有效的.bat文件。.bat文件只包含一行程序名(ssh/sftp/winver)
os.chdir( "C:\Windows\System32\OpenSSH" )
val = os.system( "dir" )

print( val )