From: Ralf Fassel on 15 Jul 2010 04:51 * "S-Y. Chen" <shenyeh_chen(a)hotmail.com> | Unfortunately that two exec'd and forked programs are all commercial | codes. We are still going through the manual, but I doubt if there | will be any help. You could try to run the file from the regular command line and see how it behaves. Does it wait for input when the error occurs? If yes, you could try to redirect stdin to an empty string: exec program_a.exe -input something.txt << "" HTH R'
From: Neil on 15 Jul 2010 10:00 On Jul 14, 10:41 pm, "S-Y. Chen" <shenyeh_c...(a)hotmail.com> wrote: > Actually the application will produce a file after it is done. And I > have deleted that file before the application is called. So, will it > be feasible to use vwait, waiting for the file to be created ? I would expect that you would be better off waiting for the process to terminate, than for the file to be created, unless it's a very simple file. If the child process creates the file, then writes to it later, and you delete it on creation, you likely have a similar issue. I've dealt with the child process issue on Windows (and not in TCL) quite a few times, and Craig's method works just fine. If you know AppA spawns off AppB, then as soon as AppA terminates, you just find AppB's process, and watch it until it ends. You can also add in anything else you need, such as killing AppB if it runs too long, or whatever.
From: Neil on 15 Jul 2010 10:04 On Jul 15, 9:00 am, Neil <neil.bry...(a)gmail.com> wrote: > On Jul 14, 10:41 pm, "S-Y. Chen" <shenyeh_c...(a)hotmail.com> wrote: > > > Actually the application will produce a file after it is done. And I > > have deleted that file before the application is called. So, will it > > be feasible to use vwait, waiting for the file to be created ? Didn't quite read that correctly the first time. It sounds like that would do nothing. If you are deleting the file, already, then it's already created; so waiting for it to be created actually won't wait... Yes? Unless I'm reading it wrong, now...
From: Alexandre Ferrieux on 15 Jul 2010 17:57 On Jul 14, 8:23 pm, "S-Y. Chen" <shenyeh_c...(a)hotmail.com> wrote: > > OK.......it seems like this program is forking. So you are right, the > exec'd one was caught but the forked one was still going on. > > Any way for my program to wait until the forked one is done ? (before > it goes on the loop and forks out more threads). One way is to arrange for the grandchild to keep an open pipe back to you until its death. This is an utter guess, but possibly the grandchild simply inherits its parent's stderr, and never closes it before dying. In this case [exec foo 2>@1] will let the "result pipe" monitor both stderrs, and will block until all offspring (even grandgrandchildren etc) has closed its stderr. Note that none of the process has to write anything interesting to stderr for this to work; only EOF detection is sought. And again, this won't work if a child closes stderr early, or if the forking process closes it even earlier (or sets its CLOEXEC flag). But doing so is not in the unix tradition. -Alex
From: S-Y. Chen on 16 Jul 2010 00:20 I think I forgot to say, this is Windows. This is the original script ################# ### BGN catch {erase file01.txt} set comsol_cmd "C:\\COMSOL35a\\bin\\comsol.exe" exec $comsol_cmd matlab -ml /nodesktop -ml /nosplash -mlr "antenna_COMSOL_01, exit" set File001 [open "file01.txt" "r"] while { [gets $File001 String001] != -1} { : : : } close $File001 ### END ################# This piece of code is inside a loop. So the child process here is a package called comsol, and the grandchild is a package called matlab. We have confirmed that, when comsol is already terminated, matlab is still going on. And only when matlab is done, the file "file01.txt" will be created and saved. Using catch can avoid the exec error, but we still have to wait for matlab to finish. Otherwise this piece of scripts will be called again and again and again, and reading file01.txt will either cause error, or just get the wrong (and old data). So if I wait for file01.txt to be open, written, and closed (but, how ?), before I open it again to read. Won't that make sure matlab is already terminated ? Thanks again for all the help. Regards S-Y. Chen
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: How top create starpack with multiple tcl files and other packages Next: hey tcl-rs how life |