473,800 Members | 2,383 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 2167
In article <fn**********@r eader2.panix.co m>, Hul Tytus <ht@panix.comwr ote:
>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.progr ammer 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.progr ammer 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**********@r eader2.panix.co m>, Hul Tytus <ht@panix.comwr ote:
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
3333
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: fwrite($stdio,"/usr/X11R6/bin/xclock -display some-other-machine:0\n"); It doesn't work. I've tried wrapping the xclock command in a shell script and a C program and still no luck. In both instances I can ssh into the remote machine and run the commands...
2
14361
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 because of a binary module which has to be compiled with Visual C 6. My scripts start with a '#!/usr/bin/env python' shebang, as God intended. Now, I assume I can make cmd.exe run foo.py by asociating *.py with the python interpreter.
1
2057
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.... and boxes under
72
4241
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 c?
2
989
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 on the sign on, list the programs available to the user. The user would select the program they want and it would load the program for them in like an MDI application. I would like to make this like an MDI form that has a Shell application that...
1
1639
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 know about something like that? or something like FF javascript console under IE (always wanted how IE execute javascript). thanks for any help Gregor
13
2265
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 program would contain lots of little utility functions which do small amounts of work. None of these would actually be run. Rather, they would be typecast as strings and those strings would be examined by the program. In otherwords, the...
12
2756
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 English before seeing any Python examples. Below is my attempt at generating ten fairly simple, representative Python programs that expose new users
0
9965
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 on my Windows PC? Ans: Other than Sysinternals Autoruns, there are only a few programs which are good enough to be used when dealing with autoruns. For more information about Sysinternals Autoruns, read Que-7 in Windows Autorun FAQs: Description....
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10276
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7580
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6813
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
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 we have to send another system
3
2945
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.