![](/img/trans.png)
[英]Windows Batch File - Batch File stops executing mid way after a command that takes a while to complete
[英]Batch script stops executing after winrs command
我有一個腳本,其中包含對winrs的調用,以便在用戶指定的目標計算機上遠程啟動.exe的執行。
我想要以下功能:
我的代碼如下:
@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.
該代碼一直執行到winrs調用為止,並確實在目標計算機上執行了.exe,但隨后看來,遠程shell仍然保持打開狀態,此后什么也不做。
如果此時我按ctrl + c,則將“ Terminate the shell?(y / n)”放置在我的日志文件中(但cmd提示符中沒有輸出),然后可以按“ y”並輸入,遠程Shell退出並在cmd提示符中出現“終止批處理作業(Y / N)”,但是最后一個echo語句從不執行。
在運行.exe之后,如何使遠程外殼程序自動關閉,並在執行該腳本的任何人的提示下回顯某種形式的腳本確認的確認?
所有幫助表示贊賞!
您正在使用執行新cmd.exe
窗口並在該新窗口中運行winrs並退出的call
。 刪除它,它將起作用。 我在末尾添加了暫停,以防您雙擊運行批處理。
@回聲關閉
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
編輯
經過一些分析,似乎該批處理正在等待程序完成,因此可以僅使用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.