Remove the -Wait
argument and pass the process arguments as an array via -ArgumentList
parameter:
Start-Process -FilePath "my.exe" -ArgumentList 'start', '--config-file', "`"$my_config_file`""
The strange quoting for $my_config_file
is required because a path may contain spaces. Start-Process
does not do automatic quoting. From the docs:
If parameters or parameter values contain a space, they need to be surrounded with escaped double quotes.
Note that you won't receive output of the started process, if that matters to you. You can redirect to a file, using parameters -RedirectStandardOutput
and -RedirectStandardError
, but you can't (easily) store the output in a variable.
A way to start a process in the background, while being able to receive its output, is to create a job.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…