How to redirect stderr to file using CMD.EXE and Shell() in VB?

I've got an app where I am calling the VB Shell function to execute a command.  In order to capture the command's output, I've actually got it running with "CMD /C myprog.exe >myprog.out" ... now that works fine usually and I get the result of the execution in the file myprog.out

However when something goes wrong, the errors the program writes don't go into the file.  In C parlance, it looks like it is writing to stderr in exceptional circumstances.

How can I redirect that output as well to a file?  Under UNIX I could specifically tell it to output a particular file number such as stderr; any way to do that with CMD.EXE under NT?

Thanks

LVL 3
cwreaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Erick37Connect With a Mentor Commented:
Microsoft Article:
"HOWTO: Create a Process for Reading and Writing to a Pipe"

http://support.microsoft.com/support/kb/articles/Q173/0/85.ASP
0
 
cwreaAuthor Commented:
BTW... when I simulate the particular command at a command prompt manually by typing "CMD /C myprog.exe >myprog.out", I can see SOME lines go to the screen (what I believe are written to stderr) and SOME lines go to the file (what I believe are written to stdout)

0
 
posbisCommented:
Works much easier.... :-)

As in UNIX you just must redirect "stderr" ot "stdout"

"CMD.EXE /C myprog.exe > myprog.out 2>&1"

Yes :-) this works under Windows NT as well *smile* but most people don't know it.

The CMD.EXE has some powerful features starting from Windows 2000/XP.
OK, they don't have the power of a BASH shell but you can do a lot believe me :-)

0
All Courses

From novice to tech pro — start learning today.