From: S-Y. Chen on
Hi all,

I posted similar question before, but didn't get a good solution about
this. Now I am trying to figure out if I can go around with this.

The problem is I am using exec to call an external program, like

exec program_a.exe -input something.txt

The program runs well, at least I got what I need. But apparently it
returned error message, and the script stop. The rest of the program
in this file was ignored. Unfortunately this was inside a loop and it
was terminated.

I know it has done what I need, and I just want to continue with the
rest of the script in this file.

Can I somehow suppress the error message from this program ?

I have tried "catch", but it didn't work. (The loop goes on, but
program_a.exe is still in the memory. Finally there are too many
program_a.exe in the memory, eating up all
the resources, and the whole system crashes.............).

Any help will be greatly appreciated.

Regards
S-Y. Chen
From: Craig on
I think you need to fix the program you're exec'ing or at least understand the
errors it is returning. If the program returns an error, but leaves a piece of
itself lying around, then it is probably broken - or you don't understand how it
works. fix or understand that problem. It's also possible that the behavior for
each exec is different based on what pieces of cruft the program is leaving
around on or in your machine.

The behavior you described for using catch is exactly what catch is designed to
do, allow your script to survive an exec error. you now need to chase down and
fix that problem. If the program is forking and exec'ing, then part of it will
continue to run after the part you exec'd returned and if the forked/exec'd
piece doesn't exit on it's own, then that describes your symptoms completely.

does this external program require other input from you to behave correctly?
what happens when you run it from a command prompt over and over again?

craig

S-Y. Chen wrote:
> Hi all,
>
> I posted similar question before, but didn't get a good solution about
> this. Now I am trying to figure out if I can go around with this.
>
> The problem is I am using exec to call an external program, like
>
> exec program_a.exe -input something.txt
>
> The program runs well, at least I got what I need. But apparently it
> returned error message, and the script stop. The rest of the program
> in this file was ignored. Unfortunately this was inside a loop and it
> was terminated.
>
> I know it has done what I need, and I just want to continue with the
> rest of the script in this file.
>
> Can I somehow suppress the error message from this program ?
>
> I have tried "catch", but it didn't work. (The loop goes on, but
> program_a.exe is still in the memory. Finally there are too many
> program_a.exe in the memory, eating up all
> the resources, and the whole system crashes.............).
>
> Any help will be greatly appreciated.
>
> Regards
> S-Y. Chen
From: S-Y. Chen on
On Jul 15, 1:47 am, Craig <ask...(a)somewhere.net> wrote:
> I think you need to fix the program you're exec'ing or at least understand the
> errors it is returning. If the program returns an error, but leaves a piece of
> itself lying around, then it is probably broken - or you don't understand how it
> works. fix or understand that problem. It's also possible that the behavior for
> each exec is different based on what pieces of cruft the program is leaving
> around on or in your machine.
>
> The behavior you described for using catch is exactly what catch is designed to
> do, allow your script to survive an exec error. you now need to chase down and
> fix that problem. If the program is forking and exec'ing, then part of it will
> continue to run after the part you exec'd returned and if the forked/exec'd
> piece doesn't exit on it's own, then that describes your symptoms completely.
>
> does this external program require other input from you to behave correctly?
> what happens when you run it from a command prompt over and over again?
>
> craig
>


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


Thanks again for the help.

Regards
S-Y. Chen








From: Craig on
below...

S-Y. Chen wrote:
> On Jul 15, 1:47 am, Craig <ask...(a)somewhere.net> wrote:
>> I think you need to fix the program you're exec'ing or at least understand the
>> errors it is returning. If the program returns an error, but leaves a piece of
>> itself lying around, then it is probably broken - or you don't understand how it
>> works. fix or understand that problem. It's also possible that the behavior for
>> each exec is different based on what pieces of cruft the program is leaving
>> around on or in your machine.
>>
>> The behavior you described for using catch is exactly what catch is designed to
>> do, allow your script to survive an exec error. you now need to chase down and
>> fix that problem. If the program is forking and exec'ing, then part of it will
>> continue to run after the part you exec'd returned and if the forked/exec'd
>> piece doesn't exit on it's own, then that describes your symptoms completely.
>>
>> does this external program require other input from you to behave correctly?
>> what happens when you run it from a command prompt over and over again?
>>
>> craig
>>
>
>
> 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.

Is this normal behavior? can you control it? what's it doing? spinning cycles?

> Any way for my program to wait until the forked one is done ? (before
> it goes on the loop and forks out more threads).

tcl's exec call does a fork and exec and connects the stdout of the exec'd
program to a file descriptor that is read into the result of exec. when that
process exits exec returns and you have no connection to any children spawned by
the call to exec - except possibly being the controlling terminal, or it's analog.

The only way I can think of to figure out if one of those children is running
is to do something like a ps and test for the name or maybe ppid if the process.
ugly. if the child has called setsid(), then tcl is no longer the controlling
terminal, and it's ppid is 1. if not, and it's parent has simply exited, then
when the child exits it will be a zombie and clog up your process table, if
you're running *nix.

it would be far cleaner to fix the program, if you can.

> Thanks again for the help.
>
> Regards
> S-Y. Chen
>
>
>
>
>
>
>
>
From: S-Y. Chen on
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.

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 ?

Thanks again for the help.


Regards
S-Y. Chen