M
M
Mercury132018-03-09 22:04:17
Programming
Mercury13, 2018-03-09 22:04:17

How to make stdout redirected in WinAPI and stderr go nowhere?

I want to run a program through WinAPI channels that slightly "shit" in stderr. Therefore, I want the stderr stream to go nowhere, and stdout to a named pipe.
There is one bit in the STARTUPINFO structure - STARTF_USESTDHANDLES. Is it possible to make one of these three descriptors be null, or the buffer emptied on overflow, or something else - but only so that the program does not stop if the buffer overflows?
REPEAT FOR SYS ADMIN. Programming! Windows API! CreateProcess!
I know what 2>nul is. And what admin replaced “medium” complexity with “simple”: WinAPI is, in principle, not a trivial thing.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
cicatrix, 2018-03-10
@cicatrix

What language?
In C#, this is much easier to do, without the Win32API at all.
On the pluses, we look at the STARTUPINFO structure

typedef struct _STARTUPINFO {
  DWORD  cb;
  LPTSTR lpReserved;
  LPTSTR lpDesktop;
  LPTSTR lpTitle;
  DWORD  dwX;
  DWORD  dwY;
  DWORD  dwXSize;
  DWORD  dwYSize;
  DWORD  dwXCountChars;
  DWORD  dwYCountChars;
  DWORD  dwFillAttribute;
  DWORD  dwFlags;
  WORD   wShowWindow;
  WORD   cbReserved2;
  LPBYTE lpReserved2;
  HANDLE hStdInput;
  HANDLE hStdOutput;
  HANDLE hStdError;
} STARTUPINFO, *LPSTARTUPINFO;

Be sure to set STARTF_USESTDHANDLES in dwFlags
After calling CreateProcess in hStdInput, hStdOutput and hStdError receive pointers to the corresponding streams.

R
res2001, 2018-03-09
@res2001

prog.exe 2>nul

K
Konstantin Tsvetkov, 2018-03-09
@tsklab

stderr stream went nowhere
2>NUL
WinAPI is, in principle, not a trivial thing.
Maybe, but the detailed description is stdin, stdout, stderr .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question