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
cwreaSoftware CraftsmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cwreaSoftware CraftsmanAuthor 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
Erick37Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.