![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||