The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 04:48 AM
Calling SHELL script from C program Chanakya.m Shell Programming and Scripting 7 09-21-2007 08:34 PM
Returning Strings from C program to Unix shell script satguyz High Level Programming 11 12-30-2005 03:41 PM
Passing Parameters and getting values back from a c program to Shell script Rajeshsu High Level Programming 5 08-22-2005 03:12 AM
Returning Values (shell Script) jennifer01 Shell Programming and Scripting 3 11-29-2001 06:31 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-04-2008
nehamore nehamore is offline
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...
  #2 (permalink)  
Old 02-04-2008
ennstate ennstate is offline
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
  #3 (permalink)  
Old 02-04-2008
mehmet_demirez mehmet_demirez is offline
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0