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 - Standard output and standard error merging to a log file

Reply
 
Old 12-11-2006   #1 (permalink)
cccstar


 
 

Standard output and standard error merging to a log file

I am using classic ASP/vbscript and a run wscript method to call a PowerShell
command line as a quick and dirty remote terminal page. I want to redirect
the successful and unsucessful outputs of powershell commands in a my.ps1
file to an output text file that would represent a kind of one-shot session
log.

When I use verb-noun >> foo.txt inside the ps_code_file.ps1 it only seems
to capture the successful outputs in the pstemplog.txt

What method are kin to the standard error and standard out redirection in a
ksh script ?


--
FYI the magic so far looks like this:
' full-command is executed by the Wscript Shell object run method
dim full_command
full_command = "%comspec% /c """ & poweshellpath & " -NoProfile -Command
" _
& chr(34)&chr(38)&chr(39) & ps_code_file_path & chr(39) _
& ps_params & chr(34) & """ "
....
' write the command about to be run into the log file with a kludge
prompt
' "PS "+$PWD+"> "+"ps_user_command" >> pstemplog.txt
ps_code_text = chr(34) & "PS " & chr(34) & "+$PWD+" _
& chr(34) & ": " & chr(34) & "+" & chr(34) & ps_user_command &
chr(34) _
& " >> " & output_file_path
ps_code_file.writeline(ps_code_text)
' insert the command and point its output to the log
' ps_user_command >> pstemplog.txt
ps_code_text = ps_user_command & " >> " & output_file_path
ps_code_file.writeline(ps_code_text)
....
set objShell = Server.CreateObject( "WScript.Shell" )
objshell_wscript_return_value = objShell.Run(full_command, 3, true)

--
Romans 12:1-3

My System SpecsSystem Spec
Old 12-11-2006   #2 (permalink)
Marco Shaw


 
 

Re: Standard output and standard error merging to a log file

> When I use verb-noun >> foo.txt inside the ps_code_file.ps1 it only seems
> to capture the successful outputs in the pstemplog.txt
>
> What method are kin to the standard error and standard out redirection in
> a
> ksh script ?


Very good ref:
http://blogs.msdn.com/powershell/arc...rvariable.aspx


My System SpecsSystem Spec
Old 12-11-2006   #3 (permalink)
cccstar


 
 

Re: How do I redirect for a session or code block?

Thanks for the help but I am still unsure of how to set the text that would
otherwise appear in red on the PS console to output log file. I wanted to
merge the error and success output text streams for the current session or
code block.
Is this the best I can do?

For example if I placed this command in a file ps_code_file.ps1
Set-Location x:nosuchdirectory -ErrorVariable xxbugs >> myscriptlog.txt
$xxbugs >> myscriptlog.txt


How can I get the
--
Romans 12:1-3


"Marco Shaw" wrote:

> > When I use verb-noun >> foo.txt inside the ps_code_file.ps1 it only seems
> > to capture the successful outputs in the pstemplog.txt
> >
> > What method are kin to the standard error and standard out redirection in
> > a
> > ksh script ?

>
> Very good ref:
> http://blogs.msdn.com/powershell/arc...rvariable.aspx
>
>
>

My System SpecsSystem Spec
Old 12-11-2006   #4 (permalink)
Keith Hill [MVP]


 
 

Re: How do I redirect for a session or code block?

"cccstar" <cccstar@discussions.microsoft.com> wrote in message
news:509F931F-13F7-4FC4-AF91-BCC9E8E7E170@microsoft.com...
> Thanks for the help but I am still unsure of how to set the text that
> would
> otherwise appear in red on the PS console to output log file. I wanted to
> merge the error and success output text streams for the current session or
> code block.
> Is this the best I can do?
>
> For example if I placed this command in a file ps_code_file.ps1
> Set-Location x:nosuchdirectory -ErrorVariable xxbugs >> myscriptlog.txt
> $xxbugs >> myscriptlog.txt
>
>
> How can I get the


function foo([int]$num) { "hi";1/$num }

foo 0 > foo.txt 2>&1

HTH
--
Keith


My System SpecsSystem Spec
Old 12-11-2006   #5 (permalink)
cccstar


 
 

Re: How do I redirect for a session or code block?

Thanks, High marks for implementing tradtions, I regret that I did not try it
the old way first!
--
Romans 12:1-3


"Keith Hill [MVP]" wrote:

> "cccstar" <cccstar@discussions.microsoft.com> wrote in message
> news:509F931F-13F7-4FC4-AF91-BCC9E8E7E170@microsoft.com...
> > Thanks for the help but I am still unsure of how to set the text that
> > would
> > otherwise appear in red on the PS console to output log file. I wanted to
> > merge the error and success output text streams for the current session or
> > code block.
> > Is this the best I can do?
> >
> > For example if I placed this command in a file ps_code_file.ps1
> > Set-Location x:nosuchdirectory -ErrorVariable xxbugs >> myscriptlog.txt
> > $xxbugs >> myscriptlog.txt
> >
> >
> > How can I get the

>
> function foo([int]$num) { "hi";1/$num }
>
> foo 0 > foo.txt 2>&1
>
> HTH
> --
> Keith
>
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Standard and Standard without Hyper-V Virtual PC
Standard use for file detail fields? Vista file management
Standard output redirecting PowerShell
Standard output encoding PowerShell
Redirection of standard out and standard error 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