Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 help and support 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 > Vista Newsgroup Archive > Misc Newsgroups > PowerShell

RB

Vista - Executing CMD.EXE from PowerShell

 
 
10-26-2007   #1 (permalink)
Stephen Wood


 

Executing CMD.EXE from PowerShell

I'd like to be able to execute the following command:

$p = [diagnostics.process]::Start("cmd.exe", "/c start /wait c:\Program
Files\Microsoft Visual Studio\VC98\Bin\VCVARS32.bat")
$p.WaitForExit()

The problem is, of course, is with the file path. When I run this command,
I get this error:

"Windows cannot find c:\Program. Make sure you typed the name correctly, and
try again. To search for a file, click the Start button, and ten click
Search."

When I attempt to get the path recognized by wrapping it in single quotation
marks, I get the same error.

Any ideas as to how to fix this?

Thanks,

Stephen

My System SpecsSystem Spec
10-26-2007   #2 (permalink)
Brandon Shell [MVP]


 

Re: Executing CMD.EXE from PowerShell

I cant test this atm but this should work
$p = [diagnostics.process]::Start("cmd.exe", "/c start /wait `"c:\Program
Files\Microsoft Visual Studio\VC98\Bin\VCVARS32.bat`"")
$p.WaitForExit()

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

SS> I'd like to be able to execute the following command:
SS>
SS> $p = [diagnostics.process]::Start("cmd.exe", "/c start /wait
SS> c:\Program
SS> Files\Microsoft Visual Studio\VC98\Bin\VCVARS32.bat")
SS> $p.WaitForExit()
SS> The problem is, of course, is with the file path. When I run this
SS> command, I get this error:
SS>
SS> "Windows cannot find c:\Program. Make sure you typed the name
SS> correctly, and try again. To search for a file, click the Start
SS> button, and ten click Search."
SS>
SS> When I attempt to get the path recognized by wrapping it in single
SS> quotation marks, I get the same error.
SS>
SS> Any ideas as to how to fix this?
SS>
SS> Thanks,
SS>
SS> Stephen
SS>


My System SpecsSystem Spec
11-01-2007   #3 (permalink)
Jeffery Hicks [MVP]


 

Re: Executing CMD.EXE from PowerShell

You might also need to escape the path if Brandon's suggestion didn't work:

$p = [diagnostics.process]::Start("cmd.exe", "/c start /wait `"c:\Program
Quote:

> Files\Microsoft` Visual` Studio\VC98\Bin\VCVARS32.bat`"")

"Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
news:29d4f6461eef8c9e5f67b4f685a@xxxxxx
Quote:

>I cant test this atm but this should work
> $p = [diagnostics.process]::Start("cmd.exe", "/c start /wait `"c:\Program
> Files\Microsoft Visual Studio\VC98\Bin\VCVARS32.bat`"")
> $p.WaitForExit()
>
> Brandon Shell
> ---------------
> Blog: http://www.bsonposh.com/
> PSH Scripts Project: www.codeplex.com/psobject
>
> SS> I'd like to be able to execute the following command:
> SS> SS> $p = [diagnostics.process]::Start("cmd.exe", "/c start /wait
> SS> c:\Program
> SS> Files\Microsoft Visual Studio\VC98\Bin\VCVARS32.bat")
> SS> $p.WaitForExit()
> SS> The problem is, of course, is with the file path. When I run this
> SS> command, I get this error:
> SS> SS> "Windows cannot find c:\Program. Make sure you typed the name
> SS> correctly, and try again. To search for a file, click the Start
> SS> button, and ten click Search."
> SS> SS> When I attempt to get the path recognized by wrapping it in single
> SS> quotation marks, I get the same error.
> SS> SS> Any ideas as to how to fix this?
> SS> SS> Thanks,
> SS> SS> Stephen
> SS>
>
My System SpecsSystem Spec
 

Thread Tools


Similar Threads for: Executing CMD.EXE from PowerShell
Thread Forum
executing.............. Live Mail
Executing PowerShell Scripts with IIS PowerShell
Executing SQL queries from Powershell PowerShell
executing powershell scripts on server PowerShell
Executing Stored Procedure from Powershell 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 47 48 49 50 51