How to start and stop a python program in C++?
<p>I am trying start another program in C++(windows).
The C++ needs to execute <code>starter.bat --debug --verbose</code>, in the <code>starter.bat</code>, it runs <code>%SF_HOME%\files\program-start.pyc %*</code>. After the program runs, how could I stop the <code>program-start.pyc</code> in C++? How to send <code>control+c</code> to it ? I cannot find it by using <code>taskList</code> in windows command line.</p>

<pre><code>    SHELLEXECUTEINFO processInfo;

processInfo.cbSize = sizeof(SHELLEXECUTEINFO);
processInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
processInfo.hwnd = NULL;
processInfo.lpVerb = NULL;
processInfo.lpFile = L"C:\\Users\\Li\\ddddp\\bin\\scripts\\dddpstart.pyc";
processInfo.lpParameters = L"--device-type  --device-serial yyyyy --device-model TEST --debug --verbose";
processInfo.lpDirectory = NULL;
processInfo.nShow = SW_MAXIMIZE;
processInfo.hInstApp = NULL;
ShellExecuteEx(&amp;processInfo);

TerminateProcess(processInfo.hProcess, 1);
</code></pre>

<p>Then a console pops up but it doesn't stop at the end of the code.</p>

<p>I'm rusty with Windows, however sending a CTRL-C to task is done using "kill", either the program (the UNIX world) or function in C (signal.h). You need the process ID of the Python task. Given how you started the Python program, it should write its PID to a file known to your C++ program, which would read that file, get the PID, and then call kill() with the PID and the signal number - SIGKILL (9) should kill it off, but other signals, such SIGHUP and SIGQUIT are less draconian and your Python program can trap those and exit gracefully.</p>

<p>If you need example code, let me know, however, once you know the "how", this is pretty straightforward.</p>

python c++ batch-file