[英]taskkill: different behaviour console vs. script
I am writing a small shutdown script for a java application. 我正在为Java应用程序编写一个小的关闭脚本。 I get the pid and then try to do the following:
我得到了pid,然后尝试执行以下操作:
taskkill /t /pid !pid!
If I am running the command from the console (typing it by hand) everything works fine. 如果我从控制台运行命令(手动键入命令),则一切正常。 I see the shutdown routine being executed in the java console and afterwards the java console is gone.
我看到关闭例程在Java控制台中执行,然后Java控制台消失了。 I sometimes see the windows "process not responding. kill now or wait" dialog after a few seconds but the dialog is automatically closed when the java program stops.
有时,几秒钟后,我会看到Windows“进程无响应。立即杀死或等待”对话框,但是当Java程序停止时,对话框自动关闭。
If i execute a bat file with the same command I immediately see the "Process not responding..." dialog. 如果我使用相同的命令执行bat文件,我会立即看到“进程无响应...”对话框。 I see the console output: "process was successfully shut down" but the java console is still open.
我看到控制台输出:“进程已成功关闭”,但Java控制台仍处于打开状态。 It didn't even initiate the shutdown sequence.
它甚至没有启动关机序列。
edit: the complete batch script 编辑:完整的批处理脚本
@echo off
setlocal enabledelayedexpansion
if exist .\lock (
set /p pid=< lock
taskkill /t /pid !pid!
)
On the command line !pid!
在命令行上
!pid!
will normally not expanded, as delayed expansion is disabled and can only be enabled by the registry ey or with cmd /V:on
. 通常不会扩展,因为已禁用延迟扩展,并且只能通过注册表ey或使用
cmd /V:on
来启用。
So at the command line !pid!
所以在命令行上
!pid!
will stay unchanged and in the batch it will be expanded to the content of the pid
variable. 将保持不变,并在批处理中将其扩展为
pid
变量的内容。
Edit As you show the correct command on the cmd line, the command in the batch must be wrong. 编辑当您在cmd行上显示正确的命令时,批处理中的命令一定是错误的。
You should add an echo after the set/p line 您应该在set / p行之后添加回显
Echo pid="!pid!"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.