Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Hide console and capture output from script?

Closed Thread
 
Thread Tools Display Modes
Old 04-02-2007   #1 (permalink)
Brian Vallelunga
Guest
 
Posts: n/a

Hide console and capture output from script?

I'm trying to figure out how to go about launching a command-line exe
from a Powershell script while capturing its output and not showing
the command window.

I currently have:

$result = (Invoke-Expression "c:\myconsoleapp.exe -param $myparam")
"The result is: $result"


While this works, a new window pops up for myconsoleapp.exe. Is there
a way to prevent this and just capture the out?

 
Old 04-03-2007   #2 (permalink)
RichS
Guest
 
Posts: n/a

RE: Hide console and capture output from script?

Not sure you can - you are invoking cmd.exe to run your console app & I can't
see a way to run it without the window
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Brian Vallelunga" wrote:

> I'm trying to figure out how to go about launching a command-line exe
> from a Powershell script while capturing its output and not showing
> the command window.
>
> I currently have:
>
> $result = (Invoke-Expression "c:\myconsoleapp.exe -param $myparam")
> "The result is: $result"
>
>
> While this works, a new window pops up for myconsoleapp.exe. Is there
> a way to prevent this and just capture the out?
>
>

 
Old 04-03-2007   #3 (permalink)
William Stacey [C# MVP]
Guest
 
Posts: n/a

Re: Hide console and capture output from script?

Maybe you could create a runspace and run the exe from it and get the
output.

--
William Stacey [C# MVP]


"Brian Vallelunga" <brian@vallelunga.com> wrote in message
news:1175559433.206504.12920@n76g2000hsh.googlegroups.com...
| I'm trying to figure out how to go about launching a command-line exe
| from a Powershell script while capturing its output and not showing
| the command window.
|
| I currently have:
|
| $result = (Invoke-Expression "c:\myconsoleapp.exe -param $myparam")
| "The result is: $result"
|
|
| While this works, a new window pops up for myconsoleapp.exe. Is there
| a way to prevent this and just capture the out?
|


 
Old 04-03-2007   #4 (permalink)
Marcel J. Ortiz [MSFT]
Guest
 
Posts: n/a

Re: Hide console and capture output from script?

Unless myconsoleapp.exe explicitly creates a new console window, it should
just inherit the current console window. Does this behavior happen only
from PowerShell?

"Brian Vallelunga" <brian@vallelunga.com> wrote in message
news:1175559433.206504.12920@n76g2000hsh.googlegroups.com...
> I'm trying to figure out how to go about launching a command-line exe
> from a Powershell script while capturing its output and not showing
> the command window.
>
> I currently have:
>
> $result = (Invoke-Expression "c:\myconsoleapp.exe -param $myparam")
> "The result is: $result"
>
>
> While this works, a new window pops up for myconsoleapp.exe. Is there
> a way to prevent this and just capture the out?
>


 
Old 04-03-2007   #5 (permalink)
Brian Vallelunga
Guest
 
Posts: n/a

Re: Hide console and capture output from script?

On Apr 3, 11:35 am, "Marcel J. Ortiz [MSFT]"
<mos...@online.microsoft.com> wrote:
> Unless myconsoleapp.exe explicitly creates a new console window, it should
> just inherit the current console window. Does this behavior happen only
> from PowerShell?
>
> "Brian Vallelunga" <b...@vallelunga.com> wrote in message
>
> news:1175559433.206504.12920@n76g2000hsh.googlegroups.com...
>
>
>
> > I'm trying to figure out how to go about launching a command-line exe
> > from a Powershell script while capturing its output and not showing
> > the command window.

>
> > I currently have:

>
> > $result = (Invoke-Expression "c:\myconsoleapp.exe -param $myparam")
> > "The result is: $result"

>
> > While this works, a new window pops up for myconsoleapp.exe. Is there
> > a way to prevent this and just capture the out?- Hide quoted text -

>
> - Show quoted text -


If I just launch a shell and type in the program name and parameters
neither CMD nor Powershell launch a new window. It only occurs when
launched via Invoke-Expression in my script that it launches a new
window.

 
 
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem grabbing console output Justin Rich PowerShell 1 07-07-2008 07:51 AM
capture command and its output hugh PowerShell 1 02-16-2008 08:40 AM
output of long lines gets split in PS console Frank PowerShell 5 05-17-2007 02:52 PM
Writing to host in functions and cmdlets - how to capture this output Keith Hill [MVP] PowerShell 1 12-30-2006 03:54 PM
function return values, console output =?Utf-8?B?ZnV6enkzMzM=?= PowerShell 3 08-22-2006 07:29 AM








Vistax64.com 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 2005-2008

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 47 48 49