#PowerShell 的 Start-Process 命令
Start-Process [-FilePath] <String> [[-ArgumentList] <String[]>]
[-WorkingDirectory <String>] [-PassThru] [-Wait]
功能
启动本机程序。默认启动后立即交回控制权,可选择等待进程结束并读取退出码。
类型
Cmdlet,属于 Microsoft.PowerShell.Management。
参数
-FilePath指定可执行程序。-WorkingDirectory指定子进程的工作目录。-ArgumentList传递程序参数。数组会被拼成以空格分隔的字符串,含空格的参数需要保留相应引号。-PassThru返回Process对象。-Wait等待进程退出。
#示例
启动子进程并读取退出码
$pwshPath = (Get-Process -Id $PID).Path
$child = Start-Process -FilePath $pwshPath `
-ArgumentList '-NoProfile -NonInteractive -Command "exit 7"' -Wait -PassThru
$child.ExitCode
7