![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#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...
|
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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 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
|
|||
|
|||
|
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. |
|||
| Google The UNIX and Linux Forums |