一个命令的输出导致下一个命令失败
Output on one command cause next one to fails
您好,我有以下脚本
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
原因失败或结果与预期的计算机名称不同,例如空行。下一个命令也失败了,有没有办法防止这种行为?忽略输出或将其重定向到其他(但也是可见的)流?
使用& 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"
}
希望对您有所帮助。
您好,我有以下脚本
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
原因失败或结果与预期的计算机名称不同,例如空行。下一个命令也失败了,有没有办法防止这种行为?忽略输出或将其重定向到其他(但也是可见的)流?
使用& 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"
}
希望对您有所帮助。