Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You use handles for stdin, stdout, and stderr. Create process with CreateProcess function to get that handles. Sample code - incomplete for your case, but good example of how to do it:</p> <pre><code>#include &lt;windows.h&gt; #include &lt;stdio.h&gt; #include &lt;tchar.h&gt; /*for test.exe #include &lt;iostream&gt; #include &lt;string&gt; */ void _tmain( int argc, TCHAR *argv[] ) { /*for test.exe std::cout &lt;&lt; "test output" &lt;&lt; std::endl; for (;;) { std::string line; std::getline(std::cin, line); std::cout &lt;&lt; "line: " &lt;&lt; line &lt;&lt; std::endl; } return;*/ STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &amp;si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &amp;pi, sizeof(pi) ); // Start the child process. if( !CreateProcess( NULL, // No module name (use command line) "test.exe", // Command line NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE 0, // No creation flags NULL, // Use parent's environment block NULL, // Use parent's starting directory &amp;si, // Pointer to STARTUPINFO structure &amp;pi ) // Pointer to PROCESS_INFORMATION structure ) { printf( "CreateProcess failed (%d)\n", GetLastError() ); return; } /* HANDLE hStdInput; HANDLE hStdOutput; HANDLE hStdError;*/ HANDLE me_hStdInput = GetStdHandle(STD_INPUT_HANDLE); HANDLE me_hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE proc_hStdInput = si.hStdInput; HANDLE proc_hStdOutput = si.hStdOutput; char buff[64]; DWORD chars; while (!ReadConsole(me_hStdInput, buff, sizeof(buff), &amp;chars, NULL)) { for (DWORD written = 0, writtenThisTime; written &lt; chars; written += writtenThisTime) if (!WriteConsole(proc_hStdOutput, buff + written, chars - written, &amp;writtenThisTime, NULL)) { //handle error - TODO } } //possibly handle error for ReadConsole - TODO // Wait until child process exits. //WaitForSingleObject( pi.hProcess, INFINITE ); // Close process and thread handles. CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); } </code></pre>
 

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