1.

Solve : Redirect Problem?

Answer»

Okay, I came across a really strange problem with a REDIRECT that I can't seem to solve. This appears a very active and knowledge FORUM, so I thought I ask here ...

I have a 3rd party console application (named ugpc) that I need to run across some files. This program displays information about the file passed to it. What I need to do is simply redirect the output to a text file. So, easy enough, I do the follow:

ugpc q:\eng\17f23342_a_solid.prt > output.txt

Oddly, doing this doesn't capture all of the output, just some of it :-? . What doesn't get captured is an error message indicating that one of the associated files couldn't be found, which, sadly, is some of the information I need to go into my output.txt.

I suspect that MAYBE the program isn't using stdout for the error message and THEREFORE the redirect can't grab it, I just don't know. Does anyone have any suggestions on how I can capture this?

Let me know if anyone needs clarification on this example, it's kind of hard to explain.

Here's a list straight from the command window of what it all looks like:


C:\>ugpc q:\eng\17f23342_a_solid.prt
File Q:\work\f17f23342_solid.prt not found
q:\eng\17f23342_a_solid.prt

C:\>ugpc q:\eng\17f23342_a_solid.prt > output.txt
File Q:\work\f17f23342_solid.prt not found

C:\>type output.txt
q:\eng\17f23342_a_solid.prt

C:\>


Thanks in advance!Your right about errors not going to stdout. Actually they go to stderr and you can redirect the errors with this notation:

ugpc q:\eng\17f23342_a_solid.prt > output.txt 2>error.txt

This may not work in all cases, but it's worth a try.

Good luck. 8-)Aww, cool. Never saw that syntax before. Sadly, I'll have to wait till Monday to see if it'll work with my app.

Much appreciate it!

Hmm, another thought. Do you think I can append the error to the output, as in:

ugpc q:\eng\17f23342_a_solid.prt >output.txt 2[highlight]>>[/highlight]output.txt It's unlikely you could have two data streams being sent to the same output device. You could concatenate the two files after your program runs:

Code: [Select]ugpc q:\eng\17f23342_a_solid.prt > output.txt 2>error.txt
copy output.txt+error.txt combine.txt

Naturally this all depends on whether the redirect for stderr works.

Good luck. 8-)Okay, the stderr redirect worked perfectly. As you suspected, I was unable to send the data to the same file at the same time, got an access violation: "The process cannot access the file because it is being used by another process."

However, the CONCATENATION worked perfectly. Of course, it'll get more complicated if there is no error output file, but I think I can manage.

Thanks for your help!



Discussion

No Comment Found