2017-07-14 29 views
0

您好我有以下脚本输出上一个命令导致未来一到失败

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或结果是不同的,那么预期的计算机名称,例如空行。下一个命令也失败了,有没有办法阻止这种行为?忽略输出或将其重定向到其他(但也是可见的)流?

回答

1

使用& 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" 
} 

希望它有帮助。

相关问题