0

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" : enter image description here

This is a photo with the .exe on the Task Manager : enter image description here

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

4
  • What happens when you run subprocess.call([r'C:\Users\Documents\kino\kino.exe']) ? I think it would be the right choice Commented Jun 10, 2020 at 20:10
  • What does kino.exe do? Could it be waiting for input on stdin? Maybe it works differently depending on if its stdin is connected to a console or not? Commented Jun 10, 2020 at 20:20
  • The same thing happens when I run subprocess.call(), but the program freezes until I close the executable. Commented Jun 11, 2020 at 6:21
  • I have a .in file (for input), a .out file (for output), the main.cpp file (which contains the c++ code) and the executable. The executable takes the input from the .in file, runs it using the .cpp file and prints the answer on the .out file. Should I post a small clip of how it works? Commented Jun 11, 2020 at 6:22

2 Answers 2

1

Or you can just do it with subprocess

import subprocess subprocess.call(["C:\\Users\\Documents\\kino\\kino.exe"])

Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

Same thing happens... The program executes but it runs in the background and it doesn't stop.
use subprocess.Popen()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.