LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-16-2009, 12:29 AM   #1
jeethu
LQ Newbie
 
Registered: Oct 2009
Posts: 14

Rep: Reputation: 3
Unhappy How to return values to C from shell if wput is success ?


hi i have a C function ( shown below) which calls a shell script.
A command in the shell script( wput) ( shown below) should return success if it is successfully sent file over the ftp network. adn the C file should make a entry in a new file (eg: sendinfo.txt) about the sent time. I want to know how the wput success is reported in the C ? that is how is the sent success returned to c ?


this is the C function which calls the script:
JNIEXPORT
void JNICALL
Java_DvrContact_gatherInfo( JNIEnv * env, jobject obj )
{
int i;
i=system("/home/srijith/DVR/main/dvr/gui/control/gather_upload_info"); printf("i=%d\n",i);
}

The C fuction is called by another openlazslo function. and this is the wput command in the script gather_upload_info :


.............................# scripts
...............................#scripts
.............................#scripts

/usr/bin/wput /var/tmp/$filename.tar.gz -t 1

............................#scripts
..........................#scripts


please mention the necessary changes in C and also in the script after the wput statements. I am already 5 days late on this part!
thnks in advance

Last edited by jeethu; 10-16-2009 at 05:18 AM.
 
Old 10-16-2009, 07:00 AM   #2
bartonski
Member
 
Registered: Jul 2006
Location: Louisville, KY
Distribution: Fedora 12, Slackware, Debian, Ubuntu Karmic, FreeBSD 7.1
Posts: 443
Blog Entries: 1

Rep: Reputation: 48
wput should return 0 on success, and something non-zero on failure, i.e. the return value from wput as if run from the shell, and system() should pass that value as its return code.

Here's an example in action:

Code:
$ cat test.c; cc -o test test.c && ./test
#include <stdio.h>

int main(void) {
    printf("The return value of system( \"/bin/true\" ) is %d\n", system("/bin/true") );
    printf("The return value of system( \"/bin/false\" ) is %d\n", system("/bin/false") );
}
The return value of system( "/bin/true" ) is 0
The return value of system( "/bin/false" ) is 256
 
Old 10-16-2009, 07:04 AM   #3
bartonski
Member
 
Registered: Jul 2006
Location: Louisville, KY
Distribution: Fedora 12, Slackware, Debian, Ubuntu Karmic, FreeBSD 7.1
Posts: 443
Blog Entries: 1

Rep: Reputation: 48
By the way, this would be better in the 'programming' forum.
 
  


Reply

Tags
return, success



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
Inconsistency in function return values Completely Clueless Programming 5 09-03-2009 09:12 AM
system() and return values PatrickNew Programming 1 02-07-2007 04:35 AM
How to use return values from system functions? kpachopoulos Programming 2 07-30-2004 03:09 AM
How to return values into an array using awk Helene Programming 1 05-01-2004 10:05 PM
How can get values return from a system call quenn Programming 1 09-16-2003 11:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:49 AM.

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
Open Source Consulting | Domain Registration