473,509 Members | 2,918 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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) */
}

Feb 1 '08 #1
5 2145
In article <fn**********@reader2.panix.com>, Hul Tytus <ht@panix.comwrote:
>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
Feb 1 '08 #2
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
Feb 1 '08 #3
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
Feb 1 '08 #4
dbr
Thanks - I had a definite feeling of being in the wrong ball park.

Hul

Richard Tobin <ri*****@cogsci.ed.ac.ukwrote:
In article <fn**********@reader2.panix.com>, Hul Tytus <ht@panix.comwrote:
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
Feb 1 '08 #5
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>
Feb 1 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3314
by: brian.vincent | last post by:
I'm trying to use the ssh2 functions to run a graphical app. I have no problem opening ssh2_shell and running something like "/bin/ls /tmp". However when I try to do something like:...
2
14342
by: Jorgen Grahn | last post by:
I couldn't think of a good solution, and it's hard to Google for... I write python command-line programs under Win2k, and I use the bash shell from Cygwin. I cannot use Cygwin's python package...
1
2045
by: rk | last post by:
Hi, I'm trying to write a cgi/perl programs to post a report like the following format in which the the user has to feed the values(nos) in the boxes under % Done Qual Rel. Stab P1 p2 P3.......
72
4125
by: Paminu | last post by:
In math this expression: (a < b) && (b < c) would be described as: a < b < c But why is it that in C these two expressions evaluate to something different for the same values of a, b and...
2
980
by: john wright | last post by:
Our company wants to standardize all our new programs. We are using .NET 2.0 and VB.NET against an Oracle Database and SQL Server Database. One suggestion was to have a single sign on and based...
1
1621
by: Grzegorz ¦lusarek | last post by:
Hi everyone. I'm looking for javascript tools for web browser like IE and OPERA. I want find something like javascript shell http://www.squarefree.com/shell/shell.html for IE and OPERA. Does anyone...
13
2227
by: Snis Pilbor | last post by:
Hello, Here is an idea I've been toying with to speed up programs but still keep them portable. It's just a very handwavey rough description right now since I haven't worked out details. The...
12
2731
by: Steve Howell | last post by:
I've always thought that the best way to introduce new programmers to Python is to show them small code examples. When you go to the tutorial, though, you have to wade through quite a bit of...
0
9932
AmberJain
by: AmberJain | last post by:
Windows Autorun FAQs: Programs dealing with autoruns Linked from the Original article- "Windows Autorun FAQs: Description". Que: Can you list programs that help me to view/modify the autoruns...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.