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

Re: cannot execute program in dir with space and argument

Closed Thread
 
Thread Tools Display Modes
Old 03-12-2008   #1 (permalink)
Shay Levi
Guest


 

Re: cannot execute program in dir with space and argument


Try this way:

$CMD = "D:\Utilities\Password Updater\PasswordUpdaterCmd.exe"
& $CMD /cf:servers.txt



-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Hi,
>
> I am trying to execute a program which resides in a directory with
> spaces in the path and a needed argument. Here is the script:
>
> $CMD = "'D:\Utilities\Password Updater\PasswordUpdaterCmd.exe'
> /cf:servers.txt"
> "command is: $CMD"
> & $CMD
> I have verified that when I manually run the exact command as the
> output from this script it works but when I actually run the script, I
> get this error:
>
> command is: 'D:\Utilities\Password Updater\PasswordUpdaterCmd.exe'
> /cf:servers.txt
> The term ''D:\Utilities\Password Updater\PasswordUpdaterCmd.exe'
> /cf:servers.txt' is not recognized as a cmdlet, function, operable
> program,
> or script file. Verify the term and try again.
> At D:\Utilities\Password Updater\test.ps1:5 char:2
> + & <<<< $CMD
> [D:\Utilities\Password Updater]:
> Any help is appreciated,
>
> Thanks,
>

Old 03-12-2008   #2 (permalink)
Brandon Shell [MVP]
Guest


 

Re: cannot execute program in dir with space and argument

Try replacing '&' with 'invoke-expression'

Brandon Shell
---------------
Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject

f> Hi,
f>
f> I am trying to execute a program which resides in a directory with
f> spaces in the path and a needed argument. Here is the script:
f>
f> $CMD = "'D:\Utilities\Password Updater\PasswordUpdaterCmd.exe'
f> /cf:servers.txt"
f> "command is: $CMD"
f> & $CMD
f> I have verified that when I manually run the exact command as the
f> output from this script it works but when I actually run the script,
f> I get this error:
f>
f> command is: 'D:\Utilities\Password Updater\PasswordUpdaterCmd.exe'
f> /cf:servers.txt
f> The term ''D:\Utilities\Password Updater\PasswordUpdaterCmd.exe'
f> /cf:servers.txt' is not recognized as a cmdlet, function, operable
f> program,
f> or script file. Verify the term and try again.
f> At D:\Utilities\Password Updater\test.ps1:5 char:2
f> + & <<<< $CMD
f> [D:\Utilities\Password Updater]:
f> Any help is appreciated,
f>
f> Thanks,
f>


Old 03-12-2008   #3 (permalink)
Brandon Shell [MVP]
Guest


 

Re: cannot execute program in dir with space and argument

Try this
& "`"D:\Utilities\Password Updater\PasswordUpdaterCmd.exe`" /cf:servers.txt"

Brandon Shell
---------------
Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject

f> That does work but why couldn't I build that into the command?
f>
f> Thanks,
f>
f> "Shay Levi" wrote:
f>
Quote:
Quote:

>> Try this way:
>>
>> $CMD = "D:\Utilities\Password Updater\PasswordUpdaterCmd.exe" & $CMD
>> /cf:servers.txt
>>
>> -----
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
Quote:

>>> Hi,
>>>
>>> I am trying to execute a program which resides in a directory with
>>> spaces in the path and a needed argument. Here is the script:
>>>
>>> $CMD = "'D:\Utilities\Password Updater\PasswordUpdaterCmd.exe'
>>> /cf:servers.txt"
>>> "command is: $CMD"
>>> & $CMD
>>> I have verified that when I manually run the exact command as the
>>> output from this script it works but when I actually run the script,
>>> I
>>> get this error:
>>> command is: 'D:\Utilities\Password Updater\PasswordUpdaterCmd.exe'
>>> /cf:servers.txt
>>> The term ''D:\Utilities\Password Updater\PasswordUpdaterCmd.exe'
>>> /cf:servers.txt' is not recognized as a cmdlet, function, operable
>>> program,
>>> or script file. Verify the term and try again.
>>> At D:\Utilities\Password Updater\test.ps1:5 char:2
>>> + & <<<< $CMD
>>> [D:\Utilities\Password Updater]:
>>> Any help is appreciated,
>>> Thanks,
>>>

Old 03-12-2008   #4 (permalink)
Shay Levi
Guest


 

Re: cannot execute program in dir with space and argument


Because it is interpreted as one long string and obviously there is no such
exe file.

If you want to execute the command with its switches embeded in a string
then use invoke-expression as Brandon suggested.


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> That does work but why couldn't I build that into the command?
>
> Thanks,
>
> "Shay Levi" wrote:
>
Quote:

>> Try this way:
>>
>> $CMD = "D:\Utilities\Password Updater\PasswordUpdaterCmd.exe" & $CMD
>> /cf:servers.txt
>>
>> -----
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
Quote:

>>> Hi,
>>>
>>> I am trying to execute a program which resides in a directory with
>>> spaces in the path and a needed argument. Here is the script:
>>>
>>> $CMD = "'D:\Utilities\Password Updater\PasswordUpdaterCmd.exe'
>>> /cf:servers.txt"
>>> "command is: $CMD"
>>> & $CMD
>>> I have verified that when I manually run the exact command as the
>>> output from this script it works but when I actually run the script,
>>> I
>>> get this error:
>>> command is: 'D:\Utilities\Password Updater\PasswordUpdaterCmd.exe'
>>> /cf:servers.txt
>>> The term ''D:\Utilities\Password Updater\PasswordUpdaterCmd.exe'
>>> /cf:servers.txt' is not recognized as a cmdlet, function, operable
>>> program,
>>> or script file. Verify the term and try again.
>>> At D:\Utilities\Password Updater\test.ps1:5 char:2
>>> + & <<<< $CMD
>>> [D:\Utilities\Password Updater]:
>>> Any help is appreciated,
>>> Thanks,
>>>

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Execute error: Type Mismatch: 'Execute' kellym-global.co.uk VB Script 2 2 Weeks Ago 10:09 AM
Execute application's exe and perform changes in Program Files - V Abhi Vista General 2 01-31-2008 07:01 PM
Pls doc how to execute an app that has embbedded space in its path Bob Landau PowerShell 1 08-18-2007 07:51 PM
Unable to download and save or execute program from Internet FrancisP Vista security 6 03-26-2007 01:56 PM
Unable to download and save or execute a program from Internet FrancisP Vista security 0 06-20-2006 07:56 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 50