约 991 字

约 5 分钟

#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

#推荐阅读

更新: 2026/11/27

作者: planc

创建: 2026/11/27