Reputation: 11
Little background: Code::Blocks is an IDE with a C++ integrated compiler. When creating a C++ project, it creates a .exe file so you can run the project.
So now I want to run that executable file using a Python script (Using VSCode). I tried subprocess.call(), subprocess.run() and subprocess.Popen(), and all of them start the background process, but it doesn't compile, so it just keeps running on the Task Manager. If I run it manually (by double-clicking it) then it opens, it closes and I get my correct answer on the output file.
This is the C++ project folder for the problem "kino" :
This is a photo with the .exe on the Task Manager :
And this is my Python code:
process = subprocess.run([r'C:\Users\Documents\kino\kino.exe'], shell = True)
I want to say that I also tried subprocess.kill(), but it should terminate on its own (and I don't get my answer).
Edit: Here is a video describing the problem
Upvotes: 0
Views: 5001
Reputation: 21
Or you can just do it with subprocess
import subprocess
subprocess.call(["C:\\Users\\Documents\\kino\\kino.exe"])
Upvotes: 1
Reputation: 190
Instead of running a subprocess you could execute the program with msdos commands:
import os
os.system('C:\Users\Documents\kino\kino.exe')
The only problem is that this will block your python script until the .exe program stops running.
Upvotes: 0