python - Python 找不到某些 Windows 可执行文件
问题描述
我似乎无法让一些特定的可执行文件在 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'
事实上,如果我进行 dir 打印,这些程序不会显示在列表中。
os.chdir( "C:\Windows\System32" )
val = os.system( "dir" )
print( val )
如果我在 OpenSSH 目录上尝试相同的操作,则无法完全找到它。
os.chdir( "C:\Windows\System32\OpenSSH" )
val = os.system( "dir" )
print( val )
正如您所期望的那样,所有这些在 python 之外都可以正常工作,并且它们也可以在 .bat 中工作。
解决方案
推荐阅读
- quickbase - 如何使用 Quickbase 正确执行类似查询
- ffmpeg - 如何使用 ffmpeg 对多个输出视频的音频进行一次编码
- javascript - 为什么 for in 循环要重新排列一些元素?
- parse-platform - 错误 localStorage 未在 referh 上定义(Nuxt Js,解析服务器)
- python - 一组列表变成整数输出
- javascript - 如何将editorjs json输出保存在数据库中并在我的节点应用程序的服务器端处理它?
- django - 在前端 PUT 请求返回内部服务器 500 错误 | Django Vue
- android - android ndk字符串拼接调用malloc函数。当我将结果返回到 JAVA 层时,我需要释放它吗?
- sqlalchemy - 在sqlalchemy中的某个组中的另一行上查询具有条件的行
- reactjs - React 中的 Webpack 无法加载带有 GLTF 扩展的 3D 模型,显示 404 not found