Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-12-2004, 07:08 PM   #1
LQ Newbie
Registered: May 2004
Posts: 23

Rep: Reputation: 15
Question c code vs shell script again?

thank's to someone who help me before, but there are some question again. how can i passing argument to shell script and how can i get return value from that when i run test?

if the c code like :

#include <stdio.h>
#include <stdlib.h>

int main()
system("/bin/csh -c ./coba apa");
return 0;

and shell script (coba) like :


echo $1
return $i

so i want "apa" can be passed to coba script and the value $i in coba can be access in test.c

please, how?
Old 05-12-2004, 09:44 PM   #2
Senior Member
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
int main()
  int coba_return;

  coba_return = WEXITSTATUS(system("/bin/csh -c ./coba apa"));
  if(coba_return == 0)
    printf("coba returned value: %d\n", coba_return);

  return 0;
This is right from 'man system':
The value returned is -1 on error (e.g. fork failed), and
the return status of the command otherwise. This latter
return status is in the format specified in wait(2).
Thus, the exit code of the command will be WEXITSTA-
TUS(status). In case /bin/sh could not be executed, the
exit status will be that of a command that does exit(127).

Last edited by itsme86; 05-12-2004 at 09:47 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can we hide the code of a Shell Script? kushalkoolwal Programming 35 03-30-2011 04:55 PM
new shell window by script or code r2d2 Programming 2 12-14-2005 01:59 PM
return value from shell script to c code? khucinx Programming 1 05-13-2004 03:43 PM
c code vs shell script? khucinx Programming 1 05-12-2004 06:06 PM
how to execute shell script with c code? khucinx Programming 3 05-04-2004 02:54 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:42 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration