[英]Batch script stops executing after winrs command
I have a script that contains a call to winrs in order to remotely start the execution of a .exe on a user specified target machine. 我有一个脚本,其中包含对winrs的调用,以便在用户指定的目标计算机上远程启动.exe的执行。
I want the following functionality: 我想要以下功能:
The code I have is as follows: 我的代码如下:
@echo off
echo -------------------------------------------------------
echo PLEASE ENTER PC NAME OF DISCONNECTED MACHINE
echo -------------------------------------------------------
SET /p pcToReconnect=
echo Attempting to contact Agent.
call winrs -r:%pcToReconnect% "C:\Path\To The\exe that I want\toExecute.exe" >> logfile.txt 2>>&1
echo Agent reconnected. Please allow ~5mins for your management console to update.
The code executes until the winrs call, and it does infact execute the .exe on the target machine, but it seems then that the remote shell just stays open doing nothing after this. 该代码一直执行到winrs调用为止,并确实在目标计算机上执行了.exe,但随后看来,远程shell仍然保持打开状态,此后什么也不做。
If I push ctrl+c at this point "Terminate the shell? (y/n)" gets placed in my logfile, (but no output in the cmd prompt) and I can then push "y" and enter, upon which the remote shell exits and "Terminate batch job (Y/N)" appears in the cmd prompt, however the last echo statement never executes. 如果此时我按ctrl + c,则将“ Terminate the shell?(y / n)”放置在我的日志文件中(但cmd提示符中没有输出),然后可以按“ y”并输入,远程Shell退出并在cmd提示符中出现“终止批处理作业(Y / N)”,但是最后一个echo语句从不执行。
How can I get the remote shell to automatically close after the .exe has been run, and echo some sort of confirmation that the script has completed on the prompt of whoever has executed it? 在运行.exe之后,如何使远程外壳程序自动关闭,并在执行该脚本的任何人的提示下回显某种形式的脚本确认的确认?
All help appreciated! 所有帮助表示赞赏!
You are using call
which executes a new cmd.exe
window and running winrs in that new window and exiting. 您正在使用执行新
cmd.exe
窗口并在该新窗口中运行winrs并退出的call
。 Remove it and it will work. 删除它,它将起作用。 I added pause at the end, in case you are running batch by double clicking it.
我在末尾添加了暂停,以防您双击运行批处理。
@echo off @回声关闭
echo -------------------------------------------------------
echo PLEASE ENTER PC NAME OF DISCONNECTED MACHINE
echo -------------------------------------------------------
SET /p pcToReconnect=
echo Attempting to contact Agent.
winrs -r:%pcToReconnect% "C:\Path\To The\exe that I want\toExecute.exe" >> logfile.txt 2>>&1
echo Agent reconnected. Please allow ~5mins for your management console to update.
pause
EDIT 编辑
After some analysis it seems that the batch is waiting for the program to finish, so it would be possible to just call it with start which should call it and return to the original prompt. 经过一些分析,似乎该批处理正在等待程序完成,因此可以仅使用start调用它,然后应调用它并返回到原始提示。
start winrs -r:%pcToReconnect% "C:\Path\To The\exe that I want\toExecute.exe" >> logfile.txt 2>>&1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.