Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 03-17-2011, 09:37 AM   #1
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
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

Old 03-17-2011, 10:49 AM   #2
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
Originally Posted by shankar.489 View Post
You really need to carefully read the man page for system. After that, you should use something like this
int run_myscript(void)
    int result;

    result = system("./myscript");

    if (-1 == result)

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

Old 03-18-2011, 12:54 AM   #3
Registered: Jan 2011
Posts: 53

Original Poster
Rep: Reputation: 0
Hai David,

thaq very much its working fro me



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

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration