0

I want to get the stderr and the stdout from excusing commands in console to x string in order to do some codes in certain stderr and stdout cases

case WM_CREATE:
            ShellExecute(0,
                         "open",
                         "cmd.exe",
                         "/C ipconfig > x",
                         0, SW_HIDE);
break;

that out result to x file also I think it is not recording stderr as it leaves the x file empty on excusing adb command

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Dasser Basyouni
  • 3,142
  • 5
  • 26
  • 50
  • 1
    It takes a fair bit more code than what you have shown. :-) See here for a sample: [Creating a Child Process with Redirected Input and Output](https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499.aspx) – Cody Gray - on strike Aug 21 '16 at 17:38
  • 1
    Possible duplicate of [Process output c Windows](http://stackoverflow.com/questions/5486762/process-output-c-windows) – Cody Gray - on strike Aug 21 '16 at 17:39

1 Answers1

0

@CodyGray, thank you for trying to help, I found the solution is to just add "2>&1" this will catch stderr and stdout like this

ShellExecute(0,
                         "open",
                         "cmd.exe",
                         "/C ipconfig > buffer.txt 2>&1",
                         0, SW_HIDE);

the solution is more simpler than what you have mentioned just need to find out how to redirect it to string

Dasser Basyouni
  • 3,142
  • 5
  • 26
  • 50
  • 1
    Well, if it were really that simple, no one would waste time writing all that code. Sure, the `2>&1` magic can redirect stderr (file descriptor 2) to stdout (file descriptor 1), but you keep oversimplifying the problem. There is no "just" redirecting it to a string. You have to read the data out of the stdout handle into a string yourself. – Cody Gray - on strike Aug 21 '16 at 18:31
  • @CodyGray thank you that was right, I will try to code your mentioned code or read the file – Dasser Basyouni Aug 21 '16 at 19:10