Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ run executable and pipe output to file
    primarykey
    data
    text
    <p>To start off with, I'm pretty new to C++.</p> <p>I am wanting to accomplish the following:</p> <ul> <li>Execute the following: "SampleApp.exe -cf test.xml"</li> <li>I need the shell that execute in hidden mode</li> <li>I need the C++ application to wait until SampleApp is finished</li> <li>If the SampleApp takes longer than X amount of time, then I need to terminate the process</li> <li>I want to pipe SampleApp's output to a file (sample.log)</li> </ul> <p>So far I have the following:</p> <pre><code>SHELLEXECUTEINFO lpExecInfo; lpExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); lpExecInfo.lpFile = L"SampleApp.exe"; lpExecInfo.fMask = SEE_MASK_DOENVSUBST|SEE_MASK_NOCLOSEPROCESS; lpExecInfo.hwnd = NULL; lpExecInfo.lpVerb = L"open"; lpExecInfo.lpParameters = L"-cf test.xml"; lpExecInfo.lpDirectory = NULL; lpExecInfo.nShow = SW_HIDE; // hide shell during execution lpExecInfo.hInstApp = (HINSTANCE) SE_ERR_DDEFAIL; ShellExecuteEx(&amp;lpExecInfo); // wait until the process is finished if (lpExecInfo.hProcess != NULL) { ::WaitForSingleObject(lpExecInfo.hProcess, INFINITE); ::CloseHandle(lpExecInfo.hProcess); } </code></pre> <p>The above code achieves everything except piping output to a file. However, I doesn't seem to be possible with ShellExecute. It seems that I need to use CreateProcess instead. I am hoping that someone with more C++ experience would be able to provide me with the CreateProcess equivalent of my code plus piping output. If not, at least confirm that what I am wanting to do is possible and point me in the right direction.</p> <p>- Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload