Question

I have to execute python script in windows command prompt

I am using the following command to run the command, so that the script opens the command prompt execute it

os.system("start /wait cmd /c {c:\\python27\\python.exe C:\\examples\\xml2html.py --dir c:\\Temp\\abcd c:\\tmp\\results.xml}")

I will be expecting a new directory called "abcd" created at that location and some output files created inside that.

When I run this command normally in the windows command prompt it works. I am not able to execute this in the script. Windows command prompt opens and terminates quickly.

Could any one let me know where exactly is it going wrong with the command please?

Was it helpful?

Solution

Unless you want to open a new console window you don't need to run cmd.exe (%COMSPEC%) in order to run another Python script as a subprocess:

import sys
from subprocess import check_call

check_call([sys.executable, "C:\\examples\\xml2html.py",
            "--dir", "c:\\Temp\\abcd", "c:\\tmp\\results.xml"])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top