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?

一曲冷凌霜 提交于 2019-12-11 14:45:21

问题


I am working on a project where I am using FFMPEG to capture video. The FFMPEG command is:

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

The link: https://www.tcl.tk/man/tcl8.5/tutorial/Tcl26.html make the use of the command:

exec myprog &

Here they have not specified what is myprog.

The link: Running shell commands in background, in a tcl proc make the use of command:

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

Here the command is not accepted as eval and exec is one after another, so it takes exec as a variable.

Help me, with the write right command which can be used to capture my video in the background with TCL version 8.0 and Windows 7.


回答1:


The problem with this line:

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

is multi-fold. Firstly, you've got a double exec (unlikely to be what you want!). Secondly, you've got a piece at the end which isn't being list protected despite running on a platform that quite often has spaces in filenames, making the filename be a bit of a timebomb waiting to go off (though I think it's not as bad on Windows 7 as it was on older versions, where common writable locations had spaces in the filename).

Now, if you were using a supported version of Tcl then we'd recommend writing that as:

exec {*}$args >> $tempFile &

(Indeed, this sort of thing was one of the key use-cases for the {*} syntax.)

However, you're on an ancient version so we have to do things the other way. It still helps that we've got the above as it guides where we need to insert non-list arguments in the overall list:

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

Yes, this is hard to read and error-prone to write. Why do you think we literally changed the base language to put in something to address that? (Hardly anyone uses eval directly any more, and that's greatly reduced the defect rate in most folks' code.)




回答2:


Here is the answer, which works on windows 7 platform, with TCL version 8.0 and FFMPEG to capture the video in background.

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.


来源:https://stackoverflow.com/questions/47321957/how-to-make-use-of-command-in-tcl-version-8-0-to-make-a-proc-or-exec-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!