如何在Windows环境中杀死TCL中的后台进程

ama*_*eur 2 tcl

我已经在Windows环境中使用Tcl的exec命令从Tcl程序中启动了iperf作为后台进程.但是,我想在将来的任意时间以编程方式从同一个Tcl程序中杀死iperf进程.我怎样才能最好地完成这个?

这是我正在使用的代码

proc runtest {  REF_WLAN_IPAddr run_time} {
    exec c:\\iperf_new\\iperf -c $REF_WLAN_IPAddr -f m -w 2M -i 1 -t $run_time  >& xx.txt & 
    # have some code after this
} 
Run Code Online (Sandbox Code Playgroud)

但是我看到iperf没有被杀死,所以控件没有转回TCL,我怎么能这样做?答案非常感谢}

sch*_*enk 6

exec如果按照您描述的方式使用,则返回子进程PID列表,但Tcl没有内置kill命令; 这些仅适用于扩展.

所以你有两个主要选择:

  1. 获取TWAPI软件包http://twapi.magicsplat.com/并使用该软件包中的end_process功能(请参阅http://twapi.magicsplat.com/process.html#end_process)

  2. 使用第二个exec并使用/ PID选项运行Windows命令taskkill

    exec [auto_execok taskkill] /PID $pid
    
    Run Code Online (Sandbox Code Playgroud)