如何在 TCL 8.0 版中使用“&”命令在后台生成 proc 或 exec 命令 运行,即在 windows 7 上并行执行?

How to make use of "&" command in TCL version 8.0 to make a proc or exec command run in background i.e in parallel on windows 7?

我正在做一个项目,我正在使用 FFMPEG 捕捉视频。 FFMPEG命令是:

ffmpeg -f dshow  -t 00:00:10 -i "video=Integrated Webcam" -b 5000k -s 1280x720 c:/test/sample.avi

link:https://www.tcl.tk/man/tcl8.5/tutorial/Tcl26.html使用命令:

exec myprog &

这里他们没有具体说明什么是myprog

link:Running shell commands in background, in a tcl proc使用命令:

 eval exec [linsert $args 0 exec] >> $tempFile &

这里不接受命令,因为evalexec是一个接一个,所以把exec作为一个变量。

帮助我,使用写入权限命令可以使用 TCL version 8.0Windows 7 在后台捕获我的视频。

这一行的问题:

eval exec [linsert $args 0 exec] >> $tempFile &

是多重的。首先,你有一个双 exec(不太可能是你想要的!)。其次,尽管 运行 在一个文件名中经常有空格的平台上,但你在最后得到了一个没有被列表保护的片段,这使得文件名有点像等待爆炸的定时炸弹(尽管我认为它在 Windows 7 上并不像在旧版本上那么糟糕,其中 common 可写位置在文件名中有空格)。

现在,如果您使用 受支持的 Tcl 版本,那么我们建议将其写为:

exec {*}$args >> $tempFile &

(事实上,这种事情是 {*} 语法的关键用例之一。)

但是,您使用的是旧版本,因此我们必须以其他方式进行操作。它仍然有助于我们获得上述内容,因为它指导我们需要在整个列表中插入非列表参数的位置:

eval [linsert [linsert $args 0 exec] end >> $tempFile &]

是的,这很难读,而且写起来容易出错。您认为我们为什么 直接更改了基础语言 来添加一些内容来解决这个问题? (几乎没有人再直接使用 eval,这大大降低了大多数人代码中的缺陷率。)

这是答案,适用于 windows 7 平台,使用 TCL 8.0 版和 FFMPEG 在后台捕获视频。

proc a {} { 

 exec ffmpeg -f dshow -t 00:00:10 -i "video=Integrated Webcam" c:/test/sample-a.avi >& c:/temp.txt & 
 
}
a

// here >& divert the, the log will be saved in temp.tet file and & helps to run the command in background.