嗨,我有以下脚本
winrs -r:test.one.two -u:test -p:'te$st' echo %computername%
winrs -r:test2.one.two -u:test -p:'te$st' echo %computername%
winrs -r:test3.one.two -u:test -p:'te$st' echo %computername%我有以下问题,如果第一个winrs命令失败,原因是cannot resolve host name或结果与预期的计算机名称不同,例如空行。下一个命令也失败了,有没有办法防止这种行为?忽略输出还是将其重定向到其他(但也可见)流?
发布于 2017-07-14 17:08:24
使用& cmd /c "winrs -r:test.one.two -u:test -p:'te$st' echo %computername% 2>&1"重定向错误,然后可以在每个级别上使用try catch。
try
{
try
{
& cmd /c "winrs -r:test.one.two -u:test -p:'te$st' echo %computername% 2>&1"
}
catch
{
"1st winrs failed"
}
try
{
& cmd /c "winrs -r:test2.one.two -u:test -p:'te$st' echo %computername% 2>&1"
}
catch
{
"2nd winrs failed"
}
try
{
& cmd /c "winrs -r:test3.one.two -u:test -p:'te$st' echo %computername% 2>&1"
}
catch
{
"3rd winrs failed"
}
}
catch
{
"Entire Script failed"
}希望能有所帮助。
https://stackoverflow.com/questions/45098620
复制相似问题