python: why does calling echo with subprocess return WindowsError 2?

后端 未结 1 1173
日久生厌
日久生厌 2021-01-19 15:51

In my program, I have a function runScript():

def runScript():
subprocess.call([\'echo\', \'hello\'])

I have seen many similar examples in

1条回答
  •  离开以前
    2021-01-19 16:57

    The echo command is built in to the Windows shell, cmd.exe. It is not an external program that can be called without the shell. Therefore, your subprocess.call() needs to specify shell=True.

    subprocess.call('echo hello', shell=True)
    

    (Also, the shell will handle splitting up the command for you, so I've used the simpler single-string style of passing the command.)

    0 讨论(0)
提交回复
热议问题