相关疑难解决方法(0)

在 Python 中使用 subprocess.call('dir') 时找不到指定的文件

我在 Windows 10 上运行以下 Python 文件:

import subprocess

subprocess.call("dir")
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

  File "A:/python-tests/subprocess_test.py", line 10, in <module>
    subprocess.call(["dir"])

  File "A:\anaconda\lib\subprocess.py", line 267, in call
    with Popen(*popenargs, **kwargs) as p:

  File "A:\anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py", line 210, in __init__
    super(SubprocessPopen, self).__init__(*args, **kwargs)

  File "A:\anaconda\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)

  File "A:\anaconda\lib\subprocess.py", line 997, in _execute_child
    startupinfo)

FileNotFoundError: [WinError 2] The system cannot find the file specified
Run Code Online (Sandbox Code Playgroud)

请注意,我在dir这里仅用作示例。我实际上想运行一个更复杂的命令,但在这种情况下我也遇到了同样的错误。

请注意,我没有使用shell=True,所以这个问题的答案不适用:Cannot find the file specified when using subprocess.call('dir', shell=True) in Python

这是第 …

python-3.x windows-10

2
推荐指数
2
解决办法
6239
查看次数

标签 统计

python-3.x ×1

windows-10 ×1