Re: Waiting on end of program execution from shell script?

From: Alan Connor (zzzzzz_at_xxx.yyy)
Date: 02/16/05


Date: Wed, 16 Feb 2005 07:21:54 GMT

On Wed, 16 Feb 2005 00:09:46 -0500, Barry Margolin
<barmar@alum.mit.edu> wrote:

> In article <GExQd.1338$IU.64@newsread3.news.pas.earthlink.net>,
> Alan Connor <zzzzzz@xxx.yyy> wrote:
>
>> On Wed, 16 Feb 2005 01:41:06 +0100, Matthias Zach
>> <zach228@fortuencity.com> wrote:
>>
>>
>> > From a shell script I want to execute a java program (e.g.
>> > myprog.class) among other commands.
>> >
>> > How do specify the program call statement in this script
>> > that:
>> >
>> > 1.) the further shell script execution should wait until the
>> > java program finishes
>>
>> Assuming bash. (you should have specified what shell you are
>> using)
>>
>> myprog.class &&
>
> Why do you need '&&'? The normal behavior of virtually all
> shells is to wait for a command to finish before executing the
> next command. No special syntax is needed.
>

That's what I was taught to use by the other pros on
comp.unix.*, when one wants to make sure that the previous
command has completely finished before the next one was executed.

But you have inspired me to take a look at man bash, and it turns
out that '&&' is the logical AND operator and only executes the
second command if the first one exits with an exit code of zero.

Which is a bit of a different thing and could definitely cause
problems with the script that the OP is apparently trying to
write, where he may be checking for other exit codes from the
first program.

For the OP: The '||' operator will execute the second
command only if the first one exits with a non-zero exit code.

Good call, Barry.

Thanks.

AC



Relevant Pages

  • Re: How to set exit code of non-console app?
    ... NOT yet returned an exit code to Windows (even though it has returned ... control to the command prompt, ... behavior does NOT occur if executing within a command script."). ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Interpreting a script without executing it
    ... I have some bash script and I want to know exactly all what it will do without executing it. ... you have the ability to control whether or not a command is executed. ... overrides into the shell. ...
    (comp.unix.shell)
  • Re: backtick and system return different exit codes
    ... >> backticks cause it is returning the correct output. ... >> want to know whether the command executed successfully. ... >> executing system ... I modified my perl script to print the exit code as: ...
    (comp.lang.perl.misc)
  • Re: ANN: literate-included.lyx
    ... But then we would need a spec for SHELL. ... Execute a shell command, using the default shell for the operating ... The argument is the command string, (caddr, u) pair, to be ... Wait until the requested process finishes executing. ...
    (comp.lang.forth)
  • RE: [PHP] exec from process (deamon) without shell
    ... Not 0 as when running it from command line. ... exec from process without shell ... PHP also uses a mini non-shell thingie to run exec. ... But the "shell less" deamon is giving the -1 exit code. ...
    (php.general)