LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 07-30-2004, 03:40 AM   #1
kpachopoulos
Member
 
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 704

Rep: Reputation: 30
How to use return values from system functions?


I 'd like to write a program with C, which uses system commands. But I also want to know the values they return to my program, in order to understand if everything went right. How do I get these values?
 
Old 07-30-2004, 03:54 AM   #2
barisdemiray
Member
 
Registered: Sep 2003
Location: Ankara/Turkey
Distribution: Slackware
Posts: 155

Rep: Reputation: 30
From the
Code:
man system
(Please refer them first ;-)):

RETURN VALUE
The value returned is -1 on error (e.g. fork failed), and the return
status of the command otherwise.

Sample:

[baris@rhinox]$ cat return.c
#include <stdlib.h>

int main(int argc, char **argv)
{
int i = system("test 4 -gt 2");

if ( i == -1 )
printf("error\n");
else
printf("$?: %d\n", i);

return 0;
}


[baris@rhinox]$ ./a.out
$?: 0
[baris@rhinox]$ test 4 -gt 2
[baris@rhinox]$ echo $?
0
 
Old 07-30-2004, 04:09 AM   #3
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 418

Rep: Reputation: 31
Are you talking about the linux system calls, the ones that reside in file:/usr/include/asm/unistd.h ? Most system calls have C wrappers
that return the values using normal C procedure. You can issue a
man nameofsystemcall to see how each is set up. If you are
calling them from assembly, they return their value in EAX with the
arguments pushed onto the stack in reverse order.
 
  


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
'load average' return values from sysinfo() bulliver Programming 4 04-05-2005 11:02 PM
Do Perl functions usually modify variables, or return modified copies? Why? johnMG Programming 3 02-06-2005 11:22 PM
return statement in functions pantera Programming 2 12-06-2004 07:21 PM
How to return values into an array using awk Helene Programming 1 05-01-2004 11:05 PM
How can get values return from a system call quenn Programming 1 09-17-2003 12:05 AM


All times are GMT -5. The time now is 08:43 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration