Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Redirection of standard out and standard error

Reply
 
Old 10-29-2006   #1 (permalink)
Olav Kindt


 
 

Redirection of standard out and standard error

All,

I know this has been debated before, but I have searched the old
postings and not found it, so I try to start a new thread on this issue.

I have a legacy application for testing that will write some of its
output to stdout, and some to stderr. I would like to capture the output
from this application so that I can parse the output for the result.

The DOS command for doing this is :

mytest1.exe > test_result.txt 2>&1
mytest2.exe >> test_result.txt 2>&1

Can this be done directly in Powershell??

I have also tried to do

function all_tests {
cmd /c "mytest1.exe > test_result.txt 2>&1"
...

}

When I dot source this file, and call the all_tests function, it hangs,
and when looking at the output in the test_result.txt file i see this:

PS> more test_result.txt
One or more CON code pages invalid for given keyboard code
File not found.
PS>

Can anyone explain to me what this means. Running the command from the
Powershell command line seems to work OK, I only get these messages when
running from a script file.


Hope someone out there can help me

Thanks

Olav

My System SpecsSystem Spec
Old 10-30-2006   #2 (permalink)
Bruce Payette [MSFT]


 
 

Re: Redirection of standard out and standard error

The commands

mytest1.exe > test_result.txt 2>&1
mytest2.exe >> test_result.txt 2>&1

should work fine in PowerShell as the redirection operators are the same.

> When I dot source this file, and call the all_tests function, it hangs,
> and when looking at the output in the test_result.txt file i see this:
>
> PS> more test_result.txt


From the above, somewhere in your all_tests function you're calling "more"
which is probably why it appears to be hanging - more is waiting for input.

-bruce

--
Bruce Payette [MSFT]
Windows PowerShell Technical Lead
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

Visit the Windows PowerShell Team blog at:
http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:
http://www.microsoft.com/technet/scr.../hubs/msh.mspx
My Book: http://manning.com/powershell

"Olav Kindt" <kindt@broadpark.no.spam> wrote in message
news:%23OB5NQ6%23GHA.4524@TK2MSFTNGP04.phx.gbl...
> All,
>
> I know this has been debated before, but I have searched the old postings
> and not found it, so I try to start a new thread on this issue.
>
> I have a legacy application for testing that will write some of its output
> to stdout, and some to stderr. I would like to capture the output from
> this application so that I can parse the output for the result.
>
> The DOS command for doing this is :
>
> mytest1.exe > test_result.txt 2>&1
> mytest2.exe >> test_result.txt 2>&1
>
> Can this be done directly in Powershell??
>
> I have also tried to do
>
> function all_tests {
> cmd /c "mytest1.exe > test_result.txt 2>&1"
> ...
>
> }
>
> When I dot source this file, and call the all_tests function, it hangs,
> and when looking at the output in the test_result.txt file i see this:
>
> PS> more test_result.txt
> One or more CON code pages invalid for given keyboard code
> File not found.
> PS>
>
> Can anyone explain to me what this means. Running the command from the
> Powershell command line seems to work OK, I only get these messages when
> running from a script file.
>
>
> Hope someone out there can help me
>
> Thanks
>
> Olav



My System SpecsSystem Spec
Old 10-30-2006   #3 (permalink)
Olav Kindt


 
 

Re: Redirection of standard out and standard error

Bruce Payette [MSFT] wrote:
> The commands
>
> mytest1.exe > test_result.txt 2>&1
> mytest2.exe >> test_result.txt 2>&1
>
> should work fine in PowerShell as the redirection operators are the same.


But they don't seem to work as expected. For testing purpose I have made
a simple program that write one line to stdout, and one line to stderr.
This is what I get when running it:


PROMPT> .\hello.exe
Hello STDOUT!
Hello STDERR!


When I do this:


PS PROMPT> .\hello.exe > mylog 2>&1
PS PROMPT> more mylog
Hello STDOUT!
hello.exe : Hello STDERR!
At line:1 char:12
+ .\hello.exe <<<< > mylog 2>&1
PS PROMPT>

As you can see the content of the file is not what I would expect.
When running the same command in a DOS shell it works fine.


>> When I dot source this file, and call the all_tests function, it hangs,
>> and when looking at the output in the test_result.txt file i see this:
>>
>> PS> more test_result.txt

>
> From the above, somewhere in your all_tests function you're calling "more"
> which is probably why it appears to be hanging - more is waiting for input.

The line more test_result.txt is just the command I used to show the
output of the command that was hanging.

Olav
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Standard and Standard without Hyper-V Virtual PC
SQL Server 2005 Standard installation error CC WMI Vista General
Made both users standard in error Vista account administration
excel workbook error / office standard 07 Microsoft Office
Standard output and standard error merging to a log file PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46