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 7511273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:30:00+00:00 2026-05-29T23:30:00+00:00

I have a C++ code that calls a test. I am doing a system

  • 0

I have a C++ code that calls a test. I am doing a system call to execute this test. When this test fails, it will display something like this ” ERROR: One or more devices of following component type(s) could not be discovered:”

I have a C++ code that runs on Linux redhat and it is capable of detecting if the system call pass or failed. But it can not capture the error message (ERROR: One or more devices of following component type(s) could not be discovered:) and append into the log file or print it.

Can someone please tell me how to capture the error message (ERROR: One or more devices of following component type(s) could not be discovered:)?
PS: I am an intern, any help would be really nice.

#include<iostream.h>
int main () 
{   
  int i;   
  if (system(NULL)) 
    puts ("Ok");   
  else 
    exit (1);

  i=system("hpsp --discover -verbose --user Admin --oapasswd password");  

  printf ("The value returned was: %d.\n",i);

  return false;
}
  • 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-05-29T23:30:04+00:00Added an answer on May 29, 2026 at 11:30 pm

    Instead of using system() use popen(). This will open a pipe capturing the standard output of the test program so that your program can read it via the pipe.

    Example EDITED:

    #define _BSD_SOURCE 1
    #define BUFFSIZE 400
    
    #include <stdio.h>
    #include <string.h>
    
    int main(int argc, char *argv[])
    {
        char *cmd = "hpsp --discover -verbose --user Admin --oapasswd password";
    
        char  buf[BUFFSIZE];
        char* searchResult;
         int  testPassed = 0;
    
        FILE *ptr;
    
        if ((ptr = popen(cmd, "r")) != NULL)
            while (fgets(buf, BUFFSIZE, ptr) != NULL)
            {
                if ((searchResult = strstr(buf, "The test passed")) != NULL )
                {
                    testPassed = 1;
                    break;
                }
            }
    
        if (testPassed)
            printf("yea!!\n");
        else
            printf("boo!!\n");
    
        pclose(ptr);
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that performs an ajax call and loads the results into
I have a function that takes another function as a parameter. Something like this
I have code that calls an ENTRY in a SUBROUTINE before the SUBROUTINE .
We have some really old code that calls WebServices using behaviours (webservice.htc), and we
I have a piece of code that calls a WCF service that is hosted
I have a legacy PHP/MySQL app that calls mysql_connect(). Tons of existing downstream code
Right now i have a line of code, in vb, that calls a text
I have the following JQuery code that worked perfect in C#/Asp.net 2.0 to call
I have the following shortened classic ASP code that makes a SQL insert call...
I have to call some code in a SharePoint site that runs under the

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.