LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 05-12-2004, 08:08 PM   #1
khucinx
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 :

/*test.c*/
#include <stdio.h>
#include <stdlib.h>

int main()
{
system("/bin/csh -c ./coba apa");
printf("succes\n");
return 0;
}

and shell script (coba) like :

#!/bin/sh

echo $1
i=10
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, 10:44 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
Code:
int main()
{
  int coba_return;

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

  return 0;
}
This is right from 'man system':
Quote:
RETURN VALUE
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 10:47 PM.
 
  


Reply


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 05:55 PM
new shell window by script or code r2d2 Programming 2 12-14-2005 02:59 PM
return value from shell script to c code? khucinx Programming 1 05-13-2004 04:43 PM
c code vs shell script? khucinx Programming 1 05-12-2004 07:06 PM
how to execute shell script with c code? khucinx Programming 3 05-04-2004 03:54 PM


All times are GMT -5. The time now is 02:24 PM.

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