Ilya Bobir wrote:
> [...]
>
> It does work on NT. But CreateProcess(..., CREATE_NO_WINDOW, ...) is
> needed. An example implementation is attached.
>
I've just found slightly different approach to creating a console for a
child process. It has an advantage of creating one console per child
thus allowing communication with more that one child process.
Here is the code:
SECURITY_ATTRIBUTES sa;
PROCESS_INFORMATION pi;
HANDLE newstdin, newstdout;
HANDLE read_stdout, write_stdin;
sa.lpSecurityDescriptor = 0;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = true;
CreatePipe(&newstdin, &write_stdin, &sa, 0);
CreatePipe(&read_stdout, &newstdout, &sa, 0);
GetStartupInfo(&si);
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE; // hide child application window
si.hStdOutput = newstdout; // use newstdout instead of STDOUT
si.hStdError = newstdout; // use newstdout instead of STDERR
si.hStdInput = newstdin; // use newstdin instead of STDIN
if(0 == CreateProcess(
exe, NULL, NULL, NULL, true, CREATE_NEW_CONSOLE,
NULL, NULL, &si, &pi))
{
printf("\nCreateProcess() fails with error: %i", GetLastError());
return -1;
}
In case pipes are in blocking mode then the PeekNamedPipe() call can be
used to check for incoming data:
if (0 == PeekNamedPipe(
read_stdout, buf, BUFSIZE - 1, &bread, &avail, NULL))
{
printf("\nPeekNamedPipe() fails with error: %i", GetLastError());
break;
}
if (bread > 0)
{
// Data have arrived
}
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---