LinuxQuestions.org
Help answer threads with 0 replies.
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 03-17-2011, 10:37 AM   #1
shankar.489
Member
 
Registered: Jan 2011
Posts: 53

Rep: Reputation: 0
Unhappy Exit status of system() call


hi folks,
i need to execute a script from my c program using
system()
or popen()
and i should able to collect its status in my code

i tried with "wait", "WEXITSTATUS" calls but iam not able to get the status correcly(getting junk)
WEXITSTATUS(system("./myscript") );

is there any to collect the status of popen or system in our code if so please let me know

i cannot use pipe for reading the status please suggest me the better possible ways

thanks in adv

~shankar
 
Old 03-17-2011, 11:49 AM   #2
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by shankar.489 View Post
WEXITSTATUS(system("./myscript"));
You really need to carefully read the man page for system. After that, you should use something like this
Code:
int run_myscript(void)
{
    int result;

    result = system("./myscript");

    if (-1 == result)
    {
        perror("system");
        exit(1);
    }

    if (127 == WEXITSTATUS(result))
    {
        fprintf(stderr, "%s", "ERROR: Could not execute /bin/sh\n");
        exit(2);
    }

    return(WEXITSTATUS(result));
}
 
Old 03-18-2011, 01:54 AM   #3
shankar.489
Member
 
Registered: Jan 2011
Posts: 53

Original Poster
Rep: Reputation: 0
Hai David,

thaq very much its working fro me

~shankar
 
  


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
Exit status vedanu Programming 4 06-23-2007 06:13 PM
Exit status of system command?? rmvinodh123 Programming 4 05-04-2007 12:15 PM
exit status naflan Programming 2 10-22-2004 01:22 PM
pppd exit status 1 wolfe2554 Linux - Networking 2 04-14-2004 01:15 AM
Using the "system( )" system call causes exit sometimes AbhiShek Linux - Software 6 10-01-2002 03:56 PM


All times are GMT -5. The time now is 10:04 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration