抱歉,我是PowerShell的新手。我正在运行一个脚本,它执行一些命令来复制系统中的文件。有没有办法捕获命令的状态是否在移动到下一个命令之前成功完成?
例如:
$scp_cmd = "scp.exe -a root@192.168.1.1:/files/repo1 /repo1"
$rsync_cmd = "rsync.exe -tvP root@192.168.1.2:/files/repo2 /repo2"
Invoke-Expression $scp_cmd
# How do we check whether the command completed successfully?
Invoke-Expression $rsync_cmd
# How do we check whether the command completed successfully?