views:

42

answers:

2

I'm trying to run console commands via subprocess.Popen, and whenever I run it I get the windows "File not found" error, even when running the echo command. I am also using Popen inside a thread made with the thread module. Is that the problem?

+1  A: 

echo is not an executable, it's an internal command inside cmd.exe. If you want to use Popen with internal commands, add a keyword parameter shell=True

grep
I put in'"D:\Program Files\Steam\steamapps\terabytest\sourcesdk\bin\orangebox\bin\vbsp.exe"'and I still get errors, it doesn't work with either shell=True or shell=FalseWhy?
Gabriele Cirulli
+1  A: 

Instead of
D:\Program Files\Steam\steamapps\terabytest\sourcesdk\bin\orangebox\bin\vbsp.exe, use
D:/Program Files/Steam/steamapps/terabytest/sourcesdk/bin/orangebox/bin/vbsp.exe

This eliminates any complications with backslashes inside quotes.

wallyk
Another major source of the problem is whitespace inside the path. It is much more robust to use a list of parameters instead of a string. Try to do something like Popen(["D:/Program Files/Steam/steamapps/terabytest/sourcesdk/bin/orangebox/bin/vbsp.exe", "param1", "param2"])
grep