A strange linux command execution problem from Process  
Author Message
Bhanu





PostPosted: 2007-5-16 20:11:00 Top

java-programmer, A strange linux command execution problem from Process Hi All,

I am using Process class to run scripts on a Fedora Core Linux
bash shell
All of my scripts are running except tho one in which i am using diff
command.

I am using simple diff command. My script is

-------------------------------------------------------------------------------------
#/bin/sh

if [ $# -eq 0 ];
then
echo "Usage: newFile oldFile outputFile"
exit
fi

FILE1=$1
FILE2=$2

OUTPUT_FILE=$3

echo "diff -c $FILE1 $FILE2 > $OUTPUT_FILE"
#diff -c $FILE1 $FILE2 > $OUTPUT_FILE

diff -c $FILE1 $FILE2 > $OUTPUT_FILE

------------------------------------------------------------------------------------------------

And I am also consuming the error and output streams so not blocking
the process.
the process returns with exit value > 0.


It would be a great help to me. If you help me solve this problem.

-Thanks,
Ratnesh.

 
Gordon Beaton





PostPosted: 2007-5-16 20:38:00 Top

java-programmer >> A strange linux command execution problem from Process On 16 May 2007 05:11:29 -0700, Bhanu wrote:
> I am using simple diff command. My script is
>
> #/bin/sh

Your script is wrong. The above line should read:

#!/bin/sh

/gordon

--
 
Nigel Wade





PostPosted: 2007-5-16 21:19:00 Top

java-programmer >> A strange linux command execution problem from Process Gordon Beaton wrote:

> On 16 May 2007 05:11:29 -0700, Bhanu wrote:
>> I am using simple diff command. My script is
>>
>> #/bin/sh
>
> Your script is wrong. The above line should read:
>
> #!/bin/sh
>

Not necessarily a problem. The original is actually a comment (whether it's
meant to be or not) so the script will be run with the default shell rather
than being forced to use /bin/sh.

As to the return value, the script/shell will return the exit status of the last
command, in this case diff. If the files differ then diff, and hence the
script, will not return 0.

--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : email***@***.com
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
 
 
Bhanu





PostPosted: 2007-5-16 22:28:00 Top

java-programmer >> A strange linux command execution problem from Process On May 16, 6:19 pm, Nigel Wade <email***@***.com> wrote:
> Gordon Beaton wrote:
> > On 16 May 2007 05:11:29 -0700, Bhanu wrote:
> >> I am using simple diff command. My script is
>
> >> #/bin/sh
>
> > Your script is wrong. The above line should read:
>
> > #!/bin/sh
>
> Not necessarily a problem. The original is actually a comment (whether it's
> meant to be or not) so the script will be run with the default shell rather
> than being forced to use /bin/sh.
>
> As to the return value, the script/shell will return the exit status of the last
> command, in this case diff. If the files differ then diff, and hence the
> script, will not return 0.
>
> --
> Nigel Wade, System Administrator, Space Plasma Physics Group,
> University of Leicester, Leicester, LE1 7RH, UK
> E-mail : email***@***.com
> Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555

Sorry for error in posting the message that line reads #!/bin/sh in
the script
somehow i did mistake while posting the message

But I figured out the error

I tried the following on command prompt

diff build.xml conf/invoker_config.xml > test.log

echo $?

and the result was amazingly 1.

 
 
Bhanu





PostPosted: 2007-5-16 22:30:00 Top

java-programmer >> A strange linux command execution problem from Process On May 16, 6:19 pm, Nigel Wade <email***@***.com> wrote:
> Gordon Beaton wrote:
> > On 16 May 2007 05:11:29 -0700, Bhanu wrote:
> >> I am using simple diff command. My script is
>
> >> #/bin/sh
>
> > Your script is wrong. The above line should read:
>
> > #!/bin/sh
>
> Not necessarily a problem. The original is actually a comment (whether it's
> meant to be or not) so the script will be run with the default shell rather
> than being forced to use /bin/sh.
>
> As to the return value, the script/shell will return the exit status of the last
> command, in this case diff. If the files differ then diff, and hence the
> script, will not return 0.
>
> --
> Nigel Wade, System Administrator, Space Plasma Physics Group,
> University of Leicester, Leicester, LE1 7RH, UK
> E-mail : email***@***.com
> Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555

The problem is something else
I just tried the following on command prompt.

diff -c build.xml conf/invoker_config.xml > test.log
echo $?

and the result was amazingly 1.


 
 
Bhanu





PostPosted: 2007-5-16 22:53:00 Top

java-programmer >> A strange linux command execution problem from Process On May 16, 6:19 pm, Nigel Wade <email***@***.com> wrote:
> Gordon Beaton wrote:
> > On 16 May 2007 05:11:29 -0700, Bhanu wrote:
> >> I am using simple diff command. My script is
>
> >> #/bin/sh
>
> > Your script is wrong. The above line should read:
>
> > #!/bin/sh
>
> Not necessarily a problem. The original is actually a comment (whether it's
> meant to be or not) so the script will be run with the default shell rather
> than being forced to use /bin/sh.
>
> As to the return value, the script/shell will return the exit status of the last
> command, in this case diff. If the files differ then diff, and hence the
> script, will not return 0.
>
> --
> Nigel Wade, System Administrator, Space Plasma Physics Group,
> University of Leicester, Leicester, LE1 7RH, UK
> E-mail : email***@***.com
> Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555

Now I found the root problem
diff command exits with 0 status only when 2 files are equal
for unequal files it returns 1.
:) ..

 
 
Lew





PostPosted: 2007-5-17 5:23:00 Top

java-programmer >> A strange linux command execution problem from Process Bhanu wrote:
> On May 16, 6:19 pm, Nigel Wade <email***@***.com> wrote:
>> Gordon Beaton wrote:
>>> On 16 May 2007 05:11:29 -0700, Bhanu wrote:
>>>> I am using simple diff command. My script is
>>>> #/bin/sh
>>> Your script is wrong. The above line should read:
>>> #!/bin/sh
>> Not necessarily a problem. The original is actually a comment (whether it's
>> meant to be or not) so the script will be run with the default shell rather
>> than being forced to use /bin/sh.
>>
>> As to the return value, the script/shell will return the exit status of the last
>> command, in this case diff. If the files differ then diff, and hence the
>> script, will not return 0.
>>
>> --
>> Nigel Wade, System Administrator, Space Plasma Physics Group,
>> University of Leicester, Leicester, LE1 7RH, UK
>> E-mail : email***@***.com
>> Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
>
> Now I found the root problem
> diff command exits with 0 status only when 2 files are equal
> for unequal files it returns 1.

You found this by reading Nigel's post, which you keep quoting, yes? The one
where he explained exactly that?

--
Lew