简体   繁体   中英

Python subprocess.call() in an .exe

I just made a python program I wrote into an exe using py2exe. Before, this code:

import subprocess
subprocess.call("C:\Windows\system32\cmd.exe", shell=True)

opened command prompt. Now, when called in the exe, it gives "The System cannot find the path specified".

I'm at a loss as to why it would do this, since the path to command prompt is not changing. Can anyone help me?

Edit: To put things into perspective, the project this is a part of can be found here . The paths.txt is where the path that is being executed is. SpeechControl.py is the main file. What I want to emphasize is that when running the python script through the python command line or cmd, it DOES work completely fine, but when I make it an executable using py2exe, it does not. The idea of the program is that an executable can be run on voice command, and having cmd.exe was just an example. I didn't mention this, but I was also testing a path to spotify, which in my case is "C:/Users/Olek/AppData/Roaming/Spotify/spotify.exe". It gave the same "The System cannot find the path specified" message.

You could try something like this

 #this executes the statement in a cmd hence launches a cmd inside a cmd
 os.system("C:/Windows/system32/cmd.exe")
 #or this holds a reference to the opened process
 result = os.popen("C:/Windows/system32/cmd.exe").read()
 #or this
 subprocess.call("C:/Windows/system32/cmd.exe", shell=True)

Good luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM