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 - Invoke-Expression executing a command with spaces

Reply
 
Old 12-06-2007   #1 (permalink)
Ashish


 
 

Invoke-Expression executing a command with spaces

I got confused with using quotes in invoke-expression command.
I am trying to run the following command from powershell..The command takes
a parameter t - template path
"%SYSTEMDRIVE%\Program Files\Sample App\Fscstarter.exe" t
"%SYSTEMDRIVE%\Templates Dir\template.fdb"

Tried different approaches but get either a token not found exception or
invalid expression error.

$templatePath = "$env:SystemDrive:\Templates Dir"
Invoke-Expression "`"$env:SystemDrive\Program Files\Sample
App\Fscstarter.exe`" t $templatePath\template.fdb"

Could someone help point out the bleeding obvious mistake i am making?

My System SpecsSystem Spec
Old 12-06-2007   #2 (permalink)
Shay Levi


 
 

Re: Invoke-Expression executing a command with spaces

Doe's this work?

& "$envrogramfiles\Sample App\Fscstarter.exe" t "$env:SystemDrive\Templates
Dir"

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic


Quote:

> I got confused with using quotes in invoke-expression command.
> I am trying to run the following command from powershell..The command
> takes
> a parameter t - template path
> "%SYSTEMDRIVE%\Program Files\Sample App\Fscstarter.exe" t
> "%SYSTEMDRIVE%\Templates Dir\template.fdb"
> Tried different approaches but get either a token not found exception
> or invalid expression error.
>
> $templatePath = "$env:SystemDrive:\Templates Dir" Invoke-Expression
> "`"$env:SystemDrive\Program Files\Sample App\Fscstarter.exe`" t
> $templatePath\template.fdb"
>
> Could someone help point out the bleeding obvious mistake i am making?
>

My System SpecsSystem Spec
Old 12-06-2007   #3 (permalink)
Jon


 
 

Re: Invoke-Expression executing a command with spaces


"Ashish" <Ashish@xxxxxx> wrote in message
news:F936BC9A-AB6B-4D09-BF86-3641925A9635@xxxxxx
Quote:

>I got confused with using quotes in invoke-expression command.
> I am trying to run the following command from powershell..The command
> takes
> a parameter t - template path
> "%SYSTEMDRIVE%\Program Files\Sample App\Fscstarter.exe" t
> "%SYSTEMDRIVE%\Templates Dir\template.fdb"
>
> Tried different approaches but get either a token not found exception or
> invalid expression error.
>
> $templatePath = "$env:SystemDrive:\Templates Dir"
> Invoke-Expression "`"$env:SystemDrive\Program Files\Sample
> App\Fscstarter.exe`" t $templatePath\template.fdb"
>
> Could someone help point out the bleeding obvious mistake i am making?



This article may also help - discusses the use of single quotes versus
double quotes with invoke-expression ....

Remoting Quoting
http://www.microsoft.com/technet/scr...h/quoting.mspx

--
Jon


My System SpecsSystem Spec
Old 12-06-2007   #4 (permalink)
Kirk Munro


 
 

Re: Invoke-Expression executing a command with spaces

Hello Ashish,

You should read this article by Keith Hill, particularly the part that
explains the why the call operator (&) is necessary to invoke an application
from a path that has spaces:
http://keithhill.spaces.live.com/Blo...A97!6058.entry

--
Kirk Munro
Poshoholic
http://poshoholic.com


"Ashish" <Ashish@xxxxxx> wrote in message
news:F936BC9A-AB6B-4D09-BF86-3641925A9635@xxxxxx
Quote:

>I got confused with using quotes in invoke-expression command.
> I am trying to run the following command from powershell..The command
> takes
> a parameter t - template path
> "%SYSTEMDRIVE%\Program Files\Sample App\Fscstarter.exe" t
> "%SYSTEMDRIVE%\Templates Dir\template.fdb"
>
> Tried different approaches but get either a token not found exception or
> invalid expression error.
>
> $templatePath = "$env:SystemDrive:\Templates Dir"
> Invoke-Expression "`"$env:SystemDrive\Program Files\Sample
> App\Fscstarter.exe`" t $templatePath\template.fdb"
>
> Could someone help point out the bleeding obvious mistake i am making?

My System SpecsSystem Spec
Old 12-06-2007   #5 (permalink)
Ashish


 
 

Re: Invoke-Expression executing a command with spaces

Thanks Shay,Jon and Kirk..The articles were indeed helpful
And yeah, Shay's suggestion works for me.

"Kirk Munro" wrote:
Quote:

> Hello Ashish,
>
> You should read this article by Keith Hill, particularly the part that
> explains the why the call operator (&) is necessary to invoke an application
> from a path that has spaces:
> http://keithhill.spaces.live.com/Blo...A97!6058.entry
>
> --
> Kirk Munro
> Poshoholic
> http://poshoholic.com
>
>
> "Ashish" <Ashish@xxxxxx> wrote in message
> news:F936BC9A-AB6B-4D09-BF86-3641925A9635@xxxxxx
Quote:

> >I got confused with using quotes in invoke-expression command.
> > I am trying to run the following command from powershell..The command
> > takes
> > a parameter t - template path
> > "%SYSTEMDRIVE%\Program Files\Sample App\Fscstarter.exe" t
> > "%SYSTEMDRIVE%\Templates Dir\template.fdb"
> >
> > Tried different approaches but get either a token not found exception or
> > invalid expression error.
> >
> > $templatePath = "$env:SystemDrive:\Templates Dir"
> > Invoke-Expression "`"$env:SystemDrive\Program Files\Sample
> > App\Fscstarter.exe`" t $templatePath\template.fdb"
> >
> > Could someone help point out the bleeding obvious mistake i am making?
>
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: running a program with spaces in Path with invoke-expression PowerShell
Re: running a program with spaces in Path with invoke-expression PowerShell
Using invoke-expression and folders containing spaces PowerShell
invoke-expression with .exe that has spaces in its path PowerShell
Issue: Invoke-Expression with $args in the expression 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