I have a python simulator file sim.py. I need to start, stop and restart this simulator from a C/C++ test file test.cpp. I tried using system( "\sim.py" ) in my test file. This starts the simulator but in the same window as test.exe. In this case how do i close the simulator alone when i want to and continue with the test? Also is it possible to open this simulator in a separate window and close it later? Please help.


call win32 api function CreateProcess() and you will have a lot more control over how the new process is created. Never tried it with a *.py program.

Thanks for the details. I tried using CreateProcess but could not get the sim.py running. Below is the code that i used. Let me know if you have any suggestions.

STARTUPINFO siStartupInfo;

memset(&siStartupInfo, 0, sizeof(siStartupInfo));
memset(&piProcessInfo, 0, sizeof(piProcessInfo));

siStartupInfo.cb = sizeof(siStartupInfo);

if(CreateProcess("C:\\sim.py", // Application name
NULL, // Application arguments
0, // Working directory
&piProcessInfo) == FALSE)
// Could not start application -> call 'GetLastError()'

I have another solution.. might not be very professional but it will work for sure. Ok as you know you are starting a new process and you certainly know the name of the process. So once the process is started, you can use "system" function again for a 'batch' file. This batch file contains a small code to kill a process you can see the 'taskkill' command for MS DOS. If you are using linux i am very sure that there will be a command to terminate a process. So if you are in a hurry you can use this technique but if you can spend more time on this task.. do it the professional way :].. hope this helps

Edited 6 Years Ago by Software guy: n/a

Thanks for all the help! I am using Create process method to start the process and use the process id thus generated to kill the process later by taskkill command and it works fine!

This question has already been answered. Start a new discussion instead.