我想要做类似于bash的东西
kill -9 `cat pid.txt`
在Windows中。我尝试过
set /p mypid= < pid.txt && taskkill /f /pid %mypid%
但它不起作用,看起来像是在执行“taskkill”命令后才分配了“%mypid%”值。如何解决?(我将从NSIS安装脚本中调用此命令,因此不想为其创建单独的“.bat”文件)。
我想要做类似于bash的东西
kill -9 `cat pid.txt`
set /p mypid= < pid.txt && taskkill /f /pid %mypid%
我不确定pid.txt文件的内容是什么,但是假设它只包含PID本身,您可以按照以下步骤进行操作:
for /f %%x in (pid.txt) do taskkill /f /pid %%x
如果您是从命令行运行代码而不是作为批处理文件的一部分,请将%%x
替换为%x
。
如果pid.txt中的内容不是这样,请编辑您的问题以更清晰地表达。
pid.txt
仅仅是进程 ID。但当我尝试运行它时,Windows 只是为我执行了记事本和 pid.txt
。 - user1569115%%x是意外的
。 - JérémyOutFile "kill.exe"
Var pid
!define filename "pid.txt"
Section
ClearErrors
FileOpen $0 "${filename}" r
IfErrors 0 readok
DetailPrint "Error to open ${filename}"
goto done
readok:
FileRead $0 $pid
DetailPrint "pid found=$pid"
FileClose $0
ExecWait 'taskkill /F /PID $pid'
done:
SectionEnd