FileNotFoundError:[WinError 2] Das System kann die angegebene Datei nicht finden

时间:2016-03-27 16:14:38

标签: python python-3.x subprocess

我目前正在学习如何使用模块select year, month, max(balance) as balance, max(SSN) keep (dense_rank first order by balance desc) as ssn from t group by year, month; ,我刚开始阅读新书。我立即得到了一条我不明白的错误信息。

subprocess

' Das System kann die angegebene Datei nicht finden'是德语: '系统无法找到指定的文件'。因为我自己是德国人,所以我没有遇到德国错误的麻烦,但我没有弄明白这里有什么问题

Traceback (most recent call last):
  File "D:/me/Python/subprocess.py", line 3, in <module>
    proc = subprocess.Popen(['echo', 'Hello there'], stdout=subprocess.PIPE)
  File "C:\Python34\lib\subprocess.py", line 859, in __init__
    restore_signals, start_new_session)
  File "C:\Python34\lib\subprocess.py", line 1112, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden

在书中他们说这段代码应该打印出“你好,那里&#39;在屏幕上,但由于某种原因,它没有。

这里有什么问题?我目前正在使用python 3.4.3,如果这对你有帮助的话。

1 个答案:

答案 0 :(得分:4)

echo不是可以执行的程序,但它是Windows命令行解释程序cmd.exe中提供的shell命令。

要执行shell命令,您需要将shell=True传递给Popen

proc = subprocess.Popen(['echo', 'Hello there'], stdout=subprocess.PIPE, shell=True)
#                                                                        ^^^^^^^^^^
相关问题