The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Returning Strings from C program to Unix shell script venkatesh_sasi High Level Programming 24 11-28-2007 01:48 AM
Calling SHELL script from C program Chanakya.m Shell Programming and Scripting 7 09-21-2007 05:34 PM
Returning Strings from C program to Unix shell script satguyz High Level Programming 11 12-30-2005 12:41 PM
Passing Parameters and getting values back from a c program to Shell script Rajeshsu High Level Programming 5 08-22-2005 12:12 AM
Returning Values (shell Script) jennifer01 Shell Programming and Scripting 3 11-29-2001 03:31 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-04-2008
Registered User
 

Join Date: Feb 2008
Posts: 1
returning values from shell script to calling C program

i m writing a c code which calls a shell script program(it is checkin whether a computer is up on lan)...now i want my shell script to return yes to my calling C code incase the computer with given ip is up...wat should i do for that?someone please help...
Reply With Quote
Forum Sponsor
  #2  
Old 02-04-2008
Registered User
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
Using exit values from the script

I have tried an workaround by passing return values from the script,

I have wrote an script to check if the mozilla process is running on the machine and i executed the script using the c/c++ program depending on the return value from the system command i process the results,

ShellScript
Code:
#!/bin/ksh
mozilla_running=0;
mozilla_running=$(ps -ef | grep mozilla | grep -v grep | wc -l)
if [[ mozilla_running -gt 0 ]] ; then
  exit $mozilla_running
else
  exit $mozilla_running
fi
And invoking the script using system command,
Code:
#include <iostream>
using namespace std;
int main() {
  string cmd_buff = "./checkMozilla.ksh" ;
  cout << "The command to be executed :" << cmd_buff << endl;
  int count = system(cmd_buff.c_str());
  count = count>>8;
  if( count > 0 ) {
    cout << "Yes running :" << count << endl;
  } else {
    cout << "Not running :" << count << endl;
  }
  return(0);
}

Thanks
Nagarajan G
Reply With Quote
  #3  
Old 02-04-2008
Registered User
 

Join Date: Dec 2007
Location: Istanbul
Posts: 23
If the return value is less than 256 , you can simply return it with the exit command:

exit <return_value>

If you want to return YES/NO , return 1/0 or vice versa.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0