Kellen Stuart
Kellen Stuart

Reputation: 8893

Start-Process powershell.exe with an argument

How do I start a new powershell instance and tell that instance to execute a certain command?

What I've tried:

(Assuming vim.exe and file.txt is in cwd)

Start-Process powershell.exe .\vim.exe .\file.txt

vim.exe is the parameter to powershell.exe

file.txt is the parameter to vim.exe

Error says:

Start-Process : A positional parameter cannot be found that accepts argument 
'.\file.txt'.At line:1 char:1
+ Start-Process powershell.exe .\vim.exe .\file.txt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand

I've also tried powershell.exe -ArgumentList {.\vim.exe .\file.txt} and no dice.

Upvotes: 2

Views: 9822

Answers (1)

TravisEz13
TravisEz13

Reputation: 2413

The Argument list is an array... say start-process doesn't know what to do with .\file.txt

Here is how I would write it

 Start-Process powershell.exe -ArgumentList @('.\vim.exe', '.\file.txt')

The following will also work, but I like the above where you explicitly say you want an array

 Start-Process powershell.exe -ArgumentList '.\vim.exe', '.\file.txt'

Upvotes: 4

Related Questions