Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7995913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:33:42+00:00 2026-06-04T14:33:42+00:00

I recently started to use linux, so I have little knowledge about it. At

  • 0

I recently started to use linux, so I have little knowledge about it. At least I know that every thing in linux is a file.

I would like to know how to catch a specific linux system return, for example if I choose install ruby (sudo apt-get -y install ruby), how can I know it was installed successfully?

char buffer[1024];
char *buf = malloc(4096);

char *pl;
FILE *fp;

if (strcmp(cmd, "ruby") == 0)
{
        fp = popen("sudo apt-get -y install ruby", "r");
}

if (fp == NULL)
{
        printf("Failed to load file\n");
        exit(0);
}

while ((pl = fgets(buffer, sizeof(buffer), fp)) != NULL)
{
        strcat(buf, buffer);
}

strcat(buf, "\n");

pclose(fp);

Then I am using popen to read the file opened, but it contains the same that is shown in terminal and I just want a ‘flag’ like OK or FAIL.

Sorry for my poor english.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:33:44+00:00Added an answer on June 4, 2026 at 2:33 pm

    The exit code of apt-get will tell you if it succeeded or not (0 means success). pclose(fp) will return the exit code, so you can do:

    if (pclose(fp) == 0) {
      // success
    } else {
      // failure
    }  
    

    You may notice, though, that now we’re not actually reading from the pipe. There’s not really any reason to have it. So like Joachim suggested, the system() function is probably a better fit for your case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently started to use Kohana and I know inheritance is in infancy
I have very recently started development on a multiplayer browser game that will use
I have recently started reading up on Grails and would like to use SQL
I have recently started using boost::exception. Now I would like to use boost::errinfo_nested_exception to
recently I just started to use python3 and realised that there alot of changes
So I just recently started learning about how databases work, how to use SQL
I have recently started to make useful use of C# extension methods. The SO
I have recently started learning wpf and am trying to use mvvm. My understanding
I have recently started to use the code cell function in MATLAB's editor and
I have recently started using VirtualBox to get my Linux environment rather than fully

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.