2

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.

Kellen Stuart
  • 7,775
  • 7
  • 59
  • 82

1 Answers1

4

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'
TravisEz13
  • 2,263
  • 1
  • 20
  • 28