我正在运行一个代码,等待WinSCP Process运行,然后等待它自动关闭。
现在我正在尝试替换psexec的常规输出:
cmd exited on <Host> with error code 0
随着输出,
WinSCP has been downloaded the files successfully.
一些我在使用Psexec的代码:
psexec \\<Host> -u <User> -p <Password> powershell Wait-Process WinSCP
我尝试使用
抛出任何输出命令 | Out-Null
仍然不起作用
答案 0 :(得分:1)
您需要捕获响应并检查其错误代码。
$response = & psexec \\<Host> -u <User> -p <Password> powershell Wait-Process WinSCP
switch -regex ($response) {
'error code 0' { $output = "WinSCP has been downloaded the files successfully." }
'error code 1' { $output = "Something else"
# Add other error codes from your application
default { $output = "Unknown error" }
}
return $output