Pass quoted argument string to Start-Process in PowerShell
Posted
by
Luke Puplett
on Server Fault
See other posts from Server Fault
or by Luke Puplett
Published on 2010-12-28T19:49:09Z
Indexed on
2010/12/28
19:55 UTC
Read the original article
Hit count: 471
powershell
Hello
I'm trying to very simply run an executable and pass a file path in as the first argument. In DOS, this would be the command:
import.exe "C:\Some Path\With\Spaces.txt"
By placing the path in quotes, the path is correctly parsed as the first token into the executable.
In PowerShell I'm using this:
$feeds = dir 'T:\Documents\Company\Product Development\Data
foreach ($feed in $feeds) { start -FilePath import.exe -ArgumentList $feed.FullName }
The problem with the Start-Process cmdlet in PowerShell is that it uses a string array for arguments, so the path is broken up and sent to the executable as separate tokens. Quotes in PowerShell force $feed.FullName to be treated literally.
Double quotes "" make PowerShell not see anything in the argument list. "The argument is null or empty." it tells me.
I expect that this is a known headache and has had a known workaround from day one.
Thanks
Luke
© Server Fault or respective owner