Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

A strange linux command execution problem from Process

Thread view: 
Bhanu - 16 May 2007 13:11 GMT
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 - 16 May 2007 13:38 GMT
> 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 - 16 May 2007 14:19 GMT
>> I am using simple diff command. My script is
>>
[quoted text clipped - 3 lines]
>
>   #!/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.

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Bhanu - 16 May 2007 15:27 GMT
> >> I am using simple diff command. My script is
>
[quoted text clipped - 17 lines]
> E-mail :    n...@ion.le.ac.uk
> 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 - 16 May 2007 15:30 GMT
> >> I am using simple diff command. My script is
>
[quoted text clipped - 17 lines]
> E-mail :    n...@ion.le.ac.uk
> 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 - 16 May 2007 15:53 GMT
> >> I am using simple diff command. My script is
>
[quoted text clipped - 17 lines]
> E-mail :    n...@ion.le.ac.uk
> 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 - 16 May 2007 22:22 GMT
>>>> I am using simple diff command. My script is
>>>> #/bin/sh
[quoted text clipped - 17 lines]
> 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?

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.