![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Redirecting Output in Powershell Hi, I would like to redirect Powershell output to standard output. Does Powershell redirect its output by default to standard output? Is there any parameter I need to indicate in my command in order to do so? Thanks, Jasmin |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Redirecting Output in Powershell Jasmin wrote: Quote: > I would like to redirect Powershell output to standard output. > Does Powershell redirect its output by default to standard output? Quote: > Is there any parameter I need to indicate in my command in order to do so? However, I'm not sure that this answers your questions. What are you trying to do? -- Hal Rottenberg Blog: http://halr9000.com Webmaster, Psi (http://psi-im.org) Co-host, PowerScripting Podcast (http://powerscripting.net) |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Redirecting Output in Powershell You can continue to use > and >> to redirect console output. But using a cmdlet like Out-File is preferred. There is also the Tee-Object cmdlet which will let you send output to a file and the console. -- Jeffery Hicks Microsoft PowerShell MVP http://www.scriptinganswers.com http://www.powershellcommunity.org Now Available: WSH and VBScript Core: TFM Coming Soon: Windows PowerShell: TFM 2nd Ed. "Jasmin" <Jasmin@xxxxxx> wrote in message news:BD2CC8C9-3118-44DA-952A-A33397B4B126@xxxxxx Quote: > Hi, > > I would like to redirect Powershell output to standard output. > Does Powershell redirect its output by default to standard output? > Is there any parameter I need to indicate in my command in order to do so? > > Thanks, > Jasmin |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Redirecting Output in Powershell Thanks Hal. I'm trying to invoke Powershell cmdlets through Java/C and extracting its output for further processing. I'm not interested in redirecting the out to a file. The problem was I wasn't able to get the output of my command (for instance: PowerShell.exe -Command "&{write-host "Test"}" ) The only command I managed to get its output was: PowerShell.exe –help. Additional information regarding the Powershell output mechanism could be very useful: How does it work? Does it buffer the output until some limit is reached or flush it in the end of the command, for example? "Hal Rottenberg" wrote: Quote: > Jasmin wrote: Quote: > > I would like to redirect Powershell output to standard output. > > Does Powershell redirect its output by default to standard output? > Yes. > Quote: > > Is there any parameter I need to indicate in my command in order to do so? > No. > > However, I'm not sure that this answers your questions. What are you trying to do? > > -- > > Hal Rottenberg > Blog: http://halr9000.com > Webmaster, Psi (http://psi-im.org) > Co-host, PowerScripting Podcast (http://powerscripting.net) > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Redirecting Output in Powershell This: PowerShell.exe -Command "&{write-host "Test"}" will work fine from a CMD prompt. But I think you are really missing something important. PowerShell is object oriented not a text based shell. At the very end of an expression you get a textual representation of the objects that remain in the pipeline. PowerShell has a cmdlet called Out-default that processes the end of the pipeline. It sends output to Out-Host which handles the formatting and data presentation to the console. Or because PowerShell is based on .NET, why not call those classes directly from Java or C? (I'm not a developer but I do know PowerShell). -- Jeffery Hicks Microsoft PowerShell MVP http://www.scriptinganswers.com http://www.powershellcommunity.org Now Available: WSH and VBScript Core: TFM Coming Soon: Windows PowerShell: TFM 2nd Ed. "Jasmin" <Jasmin@xxxxxx> wrote in message news:0E8173A1-6AD5-4EA9-AE95-E79D7CF7DBF3@xxxxxx Quote: > Thanks Hal. > > I'm trying to invoke Powershell cmdlets through Java/C and extracting its > output for further processing. I'm not interested in redirecting the out > to a > file. > The problem was I wasn't able to get the output of my command (for > instance: > PowerShell.exe -Command "&{write-host "Test"}" ) > The only command I managed to get its output was: PowerShell.exe –help. > > Additional information regarding the Powershell output mechanism could be > very useful: How does it work? Does it buffer the output until some limit > is > reached or flush it in the end of the command, for example? > > > "Hal Rottenberg" wrote: > Quote: >> Jasmin wrote: Quote: >> > I would like to redirect Powershell output to standard output. >> > Does Powershell redirect its output by default to standard output? >> Yes. >> Quote: >> > Is there any parameter I need to indicate in my command in order to do >> > so? >> No. >> >> However, I'm not sure that this answers your questions. What are you >> trying to do? >> >> -- >> >> Hal Rottenberg >> Blog: http://halr9000.com >> Webmaster, Psi (http://psi-im.org) >> Co-host, PowerScripting Podcast (http://powerscripting.net) >> |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Redirecting Output in Powershell Thanks Jeffery. I am aware of the fact PowerShell is object oriented and not text based. The question is how does this fact affect invoking cmdlets from my Java/C program? Is there any difference between a cmdlet called from CMD prompt and a cmdlet called from a Java/C program regarding getting the objects textual representation? Out-Default and Out-Host cmdlets: to the best of my knowledge, PowerShell adds them automatically. Is this correct only for CMD prompt? "Jeffery Hicks [MVP]" wrote: Quote: > This: PowerShell.exe -Command "&{write-host "Test"}" will work fine from a > CMD prompt. But I think you are really missing something important. > PowerShell is object oriented not a text based shell. At the very end of an > expression you get a textual representation of the objects that remain in > the pipeline. PowerShell has a cmdlet called Out-default that processes the > end of the pipeline. It sends output to Out-Host which handles the > formatting and data presentation to the console. > > Or because PowerShell is based on .NET, why not call those classes directly > from Java or C? (I'm not a developer but I do know PowerShell). > > -- > Jeffery Hicks > Microsoft PowerShell MVP > http://www.scriptinganswers.com > http://www.powershellcommunity.org > > Now Available: WSH and VBScript Core: TFM > Coming Soon: Windows PowerShell: TFM 2nd Ed. > "Jasmin" <Jasmin@xxxxxx> wrote in message > news:0E8173A1-6AD5-4EA9-AE95-E79D7CF7DBF3@xxxxxx Quote: > > Thanks Hal. > > > > I'm trying to invoke Powershell cmdlets through Java/C and extracting its > > output for further processing. I'm not interested in redirecting the out > > to a > > file. > > The problem was I wasn't able to get the output of my command (for > > instance: > > PowerShell.exe -Command "&{write-host "Test"}" ) > > The only command I managed to get its output was: PowerShell.exe –help. > > > > Additional information regarding the Powershell output mechanism could be > > very useful: How does it work? Does it buffer the output until some limit > > is > > reached or flush it in the end of the command, for example? > > > > > > "Hal Rottenberg" wrote: > > Quote: > >> Jasmin wrote: > >> > I would like to redirect Powershell output to standard output. > >> > Does Powershell redirect its output by default to standard output? > >> > >> Yes. > >> > >> > Is there any parameter I need to indicate in my command in order to do > >> > so? > >> > >> No. > >> > >> However, I'm not sure that this answers your questions. What are you > >> trying to do? > >> > >> -- > >> > >> Hal Rottenberg > >> Blog: http://halr9000.com > >> Webmaster, Psi (http://psi-im.org) > >> Co-host, PowerScripting Podcast (http://powerscripting.net) > >> |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Redirecting Output in Powershell Are you invoking your programs from the CMD shell or PowerShell? Although it would seem in your case all you are going to work with is text. Everything should eventually come through StdOut. -- Jeffery Hicks Microsoft PowerShell MVP http://www.scriptinganswers.com http://www.powershellcommunity.org Now Available: WSH and VBScript Core: TFM Coming Soon: Windows PowerShell: TFM 2nd Ed. "Jasmin" <Jasmin@xxxxxx> wrote in message news:757BB548-73B5-4644-9393-FC82714F1A78@xxxxxx Quote: > Thanks Jeffery. > > I am aware of the fact PowerShell is object oriented and not text based. > The question is how does this fact affect invoking cmdlets from my Java/C > program? > Is there any difference between a cmdlet called from CMD prompt and a > cmdlet > called from a Java/C program regarding getting the objects textual > representation? > Out-Default and Out-Host cmdlets: to the best of my knowledge, PowerShell > adds them automatically. Is this correct only for CMD prompt? > > > "Jeffery Hicks [MVP]" wrote: > Quote: >> This: PowerShell.exe -Command "&{write-host "Test"}" will work fine from >> a >> CMD prompt. But I think you are really missing something important. >> PowerShell is object oriented not a text based shell. At the very end of >> an >> expression you get a textual representation of the objects that remain in >> the pipeline. PowerShell has a cmdlet called Out-default that processes >> the >> end of the pipeline. It sends output to Out-Host which handles the >> formatting and data presentation to the console. >> >> Or because PowerShell is based on .NET, why not call those classes >> directly >> from Java or C? (I'm not a developer but I do know PowerShell). >> >> -- >> Jeffery Hicks >> Microsoft PowerShell MVP >> http://www.scriptinganswers.com >> http://www.powershellcommunity.org >> >> Now Available: WSH and VBScript Core: TFM >> Coming Soon: Windows PowerShell: TFM 2nd Ed. >> "Jasmin" <Jasmin@xxxxxx> wrote in message >> news:0E8173A1-6AD5-4EA9-AE95-E79D7CF7DBF3@xxxxxx Quote: >> > Thanks Hal. >> > >> > I'm trying to invoke Powershell cmdlets through Java/C and extracting >> > its >> > output for further processing. I'm not interested in redirecting the >> > out >> > to a >> > file. >> > The problem was I wasn't able to get the output of my command (for >> > instance: >> > PowerShell.exe -Command "&{write-host "Test"}" ) >> > The only command I managed to get its output was: PowerShell.exe –help. >> > >> > Additional information regarding the Powershell output mechanism could >> > be >> > very useful: How does it work? Does it buffer the output until some >> > limit >> > is >> > reached or flush it in the end of the command, for example? >> > >> > >> > "Hal Rottenberg" wrote: >> > >> >> Jasmin wrote: >> >> > I would like to redirect Powershell output to standard output. >> >> > Does Powershell redirect its output by default to standard output? >> >> >> >> Yes. >> >> >> >> > Is there any parameter I need to indicate in my command in order to >> >> > do >> >> > so? >> >> >> >> No. >> >> >> >> However, I'm not sure that this answers your questions. What are you >> >> trying to do? >> >> >> >> -- >> >> >> >> Hal Rottenberg >> >> Blog: http://halr9000.com >> >> Webmaster, Psi (http://psi-im.org) >> >> Co-host, PowerScripting Podcast (http://powerscripting.net) >> >> |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Redirecting Output in Powershell Ok, so you are not calling powershell.exe , you are using java via com to host the powershell engine? 2 things 1) if you are calling powershell.exe with something, the output you will get is plain console output, and should be no different than calling any other console application 2) if you somehow manage to host powershell in java via com, then WOW.. in that case you'll probably get some sort of com proxy objects wrapping the actual collection of objects being returned by powershell. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Standard output redirecting | PowerShell | |||
| Redirecting output to log file | PowerShell | |||
| redirecting standar output when using [System.Diagnostics.Process]::Start | PowerShell | |||
| redirecting file output to .exe | PowerShell | |||
| FEATURE REQUEST: redirecting output to non-file objects | PowerShell | |||