PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > c programs & shell conditionals
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
c programs & shell conditionals

Réponse
 
LinkBack Outils de la discussion
Vieux 01/02/2008, 15h29   #1
Hul Tytus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut c programs & shell conditionals

comp.lang.c
c programs & shell conditionals

How is a unix shell script made to respond to the value returned
by a program compiled from c code?
The shell script below is my current effort, which doesn't work.
The c code shows what was used to generate a.out, seen in the shell script.
The value returned was varied from 0 to 1 for testing.


---- shell script
# if [ `/net/u/12/b/br/unet/a.out` > 0 ]
if [ `/net/u/12/b/br/unet/a.out` > /dev/null ]
then echo "result is positive"
else echo "result is not greater than zero"
fi

--- c program
int main(int argc, char **argv)
{
return 1; /* or return 0 or exit(0) or exit(1) */
}

  Réponse avec citation
Vieux 01/02/2008, 15h37   #2
dj3vande@csclub.uwaterloo.ca.invalid
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c programs & shell conditionals

In article <fnvdte$se2$1@reader2.panix.com>, Hul Tytus <ht@panix.com> wrote:
>comp.lang.c


> How is a unix shell script made to respond to the value returned
>by a program compiled from c code?
> The shell script below is my current effort, which doesn't work.
>The c code shows what was used to generate a.out, seen in the shell script.
>The value returned was varied from 0 to 1 for testing.


[re-ordered]

>--- c program
>int main(int argc, char **argv)
>{
> return 1; /* or return 0 or exit(0) or exit(1) */
>}


Nothing wrong here, except that EXIT_FAILURE is probably better than 1
(though there's a good chance that the value of EXIT_FAILURE is in fact
1 on your platform).


>---- shell script
># if [ `/net/u/12/b/br/unet/a.out` > 0 ]
>if [ `/net/u/12/b/br/unet/a.out` > /dev/null ]


The people in comp.unix.shell will probably tell you that this line is
wrong.


dave

--
Dave Vandervies dj3vande at eskimo dot com

Their failure is not your excuse; time to find an unaverage pub.
--Richard Bos in the scary devil monastery
  Réponse avec citation
Vieux 01/02/2008, 15h41   #3
Richard Tobin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c programs & shell conditionals

In article <fnvdte$se2$1@reader2.panix.com>, Hul Tytus <ht@panix.com> wrote:

>if [ `/net/u/12/b/br/unet/a.out` > /dev/null ]
>then echo "result is positive"
>else echo "result is not greater than zero"
>fi


You just want

if /net/u/12/b/br/unet/a.out
then ...

-- Richard
--
:wq
  Réponse avec citation
Vieux 01/02/2008, 15h43   #4
Joachim Schmitz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c programs & shell conditionals

Hul Tytus wrote:
> comp.lang.c
> c programs & shell conditionals
>
> How is a unix shell script made to respond to the value returned
> by a program compiled from c code?
> The shell script below is my current effort, which doesn't work.
> The c code shows what was used to generate a.out, seen in the shell
> script. The value returned was varied from 0 to 1 for testing.
>
>
> ---- shell script
> # if [ `/net/u/12/b/br/unet/a.out` > 0 ]
> if [ `/net/u/12/b/br/unet/a.out` > /dev/null ]
> then echo "result is positive"
> else echo "result is not greater than zero"
> fi
>
> --- c program
> int main(int argc, char **argv)
> {
> return 1; /* or return 0 or exit(0) or exit(1) */
> }

OT here, comp.unix.programmer or comp.unix.shell might be more apropriate,
but the shell conditionals work diffeent from the C ones, in C non-zero is
true, in shell zero is true.

To make it topical: the only portable return values of main(), resp.
parameters of exit() are 0, EXIT_SUCCESS (which are equivalent) and
EXIT_FAILURE (which usually is 1, but doesn't have to be)

Bye, Jojo


  Réponse avec citation
Vieux 01/02/2008, 15h46   #5
Joachim Schmitz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c programs & shell conditionals

Joachim Schmitz wrote:
> Hul Tytus wrote:
>> comp.lang.c
>> c programs & shell conditionals
>>
>> How is a unix shell script made to respond to the value returned
>> by a program compiled from c code?
>> The shell script below is my current effort, which doesn't work.
>> The c code shows what was used to generate a.out, seen in the shell
>> script. The value returned was varied from 0 to 1 for testing.
>>
>>
>> ---- shell script
>> # if [ `/net/u/12/b/br/unet/a.out` > 0 ]
>> if [ `/net/u/12/b/br/unet/a.out` > /dev/null ]
>> then echo "result is positive"
>> else echo "result is not greater than zero"
>> fi
>>
>> --- c program
>> int main(int argc, char **argv)
>> {
>> return 1; /* or return 0 or exit(0) or exit(1) */
>> }

> OT here, comp.unix.programmer or comp.unix.shell might be more
> apropriate, but the shell conditionals work diffeent from the C ones,
> in C non-zero is true, in shell zero is true.

Uhh...perils of answering OT questions...
the `cmd` syntax would require your progarm to print a value. And in that
case redirecting the output to /dev/null doesn't make sense and also you'd
need something to test thie against

> To make it topical: the only portable return values of main(), resp.
> parameters of exit() are 0, EXIT_SUCCESS (which are equivalent) and
> EXIT_FAILURE (which usually is 1, but doesn't have to be)


Bye, Jojo


  Réponse avec citation
Vieux 01/02/2008, 16h18   #6
dbr@kbrx.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c programs & shell conditionals

Thanks Jojo - I'll give that a try. Do you know what .h file contains
the definitions for EXIT_xxx?

Hul

Joachim Schmitz <nospam.jojo@schmitz-digital.de> wrote:
> Hul Tytus wrote:
> > comp.lang.c
> > c programs & shell conditionals
> >
> > How is a unix shell script made to respond to the value returned
> > by a program compiled from c code?
> > The shell script below is my current effort, which doesn't work.
> > The c code shows what was used to generate a.out, seen in the shell
> > script. The value returned was varied from 0 to 1 for testing.
> >
> >
> > ---- shell script
> > # if [ `/net/u/12/b/br/unet/a.out` > 0 ]
> > if [ `/net/u/12/b/br/unet/a.out` > /dev/null ]
> > then echo "result is positive"
> > else echo "result is not greater than zero"
> > fi
> >
> > --- c program
> > int main(int argc, char **argv)
> > {
> > return 1; /* or return 0 or exit(0) or exit(1) */
> > }

> OT here, comp.unix.programmer or comp.unix.shell might be more apropriate,
> but the shell conditionals work diffeent from the C ones, in C non-zero is
> true, in shell zero is true.


> To make it topical: the only portable return values of main(), resp.
> parameters of exit() are 0, EXIT_SUCCESS (which are equivalent) and
> EXIT_FAILURE (which usually is 1, but doesn't have to be)


> Bye, Jojo



  Réponse avec citation
Vieux 01/02/2008, 16h20   #7
dbr@kbrx.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c programs & shell conditionals

Thanks - I had a definite feeling of being in the wrong ball park.

Hul

Richard Tobin <richard@cogsci.ed.ac.uk> wrote:
> In article <fnvdte$se2$1@reader2.panix.com>, Hul Tytus <ht@panix.com> wrote:


> >if [ `/net/u/12/b/br/unet/a.out` > /dev/null ]
> >then echo "result is positive"
> >else echo "result is not greater than zero"
> >fi


> You just want


> if /net/u/12/b/br/unet/a.out
> then ...


> -- Richard
> --
> :wq

  Réponse avec citation
Vieux 01/02/2008, 16h21   #8
dbr@kbrx.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c programs & shell conditionals

Thanks, Hul

dj3vande@csclub.uwaterloo.ca.invalid wrote:
> In article <fnvdte$se2$1@reader2.panix.com>, Hul Tytus <ht@panix.com> wrote:
> >comp.lang.c


> > How is a unix shell script made to respond to the value returned
> >by a program compiled from c code?
> > The shell script below is my current effort, which doesn't work.
> >The c code shows what was used to generate a.out, seen in the shell script.
> >The value returned was varied from 0 to 1 for testing.


> [re-ordered]


> >--- c program
> >int main(int argc, char **argv)
> >{
> > return 1; /* or return 0 or exit(0) or exit(1) */
> >}


> Nothing wrong here, except that EXIT_FAILURE is probably better than 1
> (though there's a good chance that the value of EXIT_FAILURE is in fact
> 1 on your platform).



> >---- shell script
> ># if [ `/net/u/12/b/br/unet/a.out` > 0 ]
> >if [ `/net/u/12/b/br/unet/a.out` > /dev/null ]


> The people in comp.unix.shell will probably tell you that this line is
> wrong.



> dave


> --
> Dave Vandervies dj3vande at eskimo dot com


> Their failure is not your excuse; time to find an unaverage pub.
> --Richard Bos in the scary devil monastery

  Réponse avec citation
Vieux 01/02/2008, 16h26   #9
Joachim Schmitz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c programs & shell conditionals

dbr@kbrx.com wrote:
> Thanks Jojo - I'll give that a try. Do you know what .h file contains
> the definitions for EXIT_xxx?
>

a quick grep would show...

but it should be stdlib.h

Bye, Jojo


  Réponse avec citation
Vieux 01/02/2008, 16h48   #10
Mark Bluemel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c programs & shell conditionals

Hul Tytus wrote:
> comp.lang.c
> c programs & shell conditionals
>
> How is a unix shell script made to respond to the value returned
> by a program compiled from c code?



<OT>

I recommend, though it's old and possibly out of print, getting hold of
"The Unix Programming Environment" by Kernighan and Pike.

A very short book but, as is usual when Brian Kernighan's involved, a
very clear and useful text. This sort of issue is covered.

</OT>
  Réponse avec citation
Vieux 01/02/2008, 20h18   #11
Keith Thompson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c programs & shell conditionals

"Joachim Schmitz" <nospam.jojo@schmitz-digital.de> writes:
> dbr@kbrx.com wrote:
>> Thanks Jojo - I'll give that a try. Do you know what .h file contains
>> the definitions for EXIT_xxx?
>>

> a quick grep would show...
>
> but it should be stdlib.h


A quick grep could easily show something irrelevant like, say, a C++
"cstdlib" header, or some other system header from which <stdlib.h>
gets the EXIT_SUCCESS and EXIT_FAILURE definitions, and which might
not exist on another platform. <stdlib.h> is the right header to
include in your program. (The documentation for the exit() function
or a good C reference should tell you this.)

--
Keith Thompson (The_Other_Keith) <kst-u@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 23h10.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,59075 seconds with 19 queries