简体   繁体   中英

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?

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 .

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.)

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. 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM