0

How can I use PowerShell's Start-Process cmdlet to start a process using its full command line (with executable path and arguments). For instance let I have the following line

"<dir_path>/myprog.exe" -arg1 "val1" -arg2 "val2"

stored on some string variable and want to run it via Start-Process.

I know that Start-Process -FilePath '<dir_path>/myprog.exe' -ArgumentList '-arg1 "val1" -arg2 "val2"' will work. But the point is that I don't know how to get executable's path and arguments from the full command line.

So is there some way to run process using its full command line via Start-Process, or if there is no such way, then how can I get file path and argument list from the command line?

Mihran Hovsepyan
  • 10,810
  • 14
  • 61
  • 111

2 Answers2

0

Do you need start-process? Can you invoke the executable directly?

& "C:\Dir 1\Dir 2\executable.exe" -arg1 "value 1" -arg2 "value 2"

See help about_Operators and for info on & (call) operator.

Bill

Bill_Stewart
  • 22,916
  • 4
  • 51
  • 62
0

Is there some reason you have your heart set on Start-Process? If not, you can do this:

Invoke-Expression "& $command"

where $command is the variable that stores the full command line.

Adi Inbar
  • 12,097
  • 13
  • 56
  • 69