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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:57:33+00:00 2026-05-10T18:57:33+00:00

I need to run a Linux CLI command and get its stdout output from

  • 0

I need to run a Linux CLI command and get its stdout output from C.

I can use pipe() to create a pipe, then fork/exec, redirecting child’s stdout descriptor into the pipe before calling exec(), and reading from the pipe in parent. Plus I’ll need to wait on the child.

Is there a simple call to do fork + redirect + exec + wait, like system() does fork + exec + wait, only system() doesn’t do the redirect.

There’s popen(), which does fork + redirect + exec, but doesn’t do wait, so I can’t get exit status.

  • 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. 2026-05-10T18:57:34+00:00Added an answer on May 10, 2026 at 6:57 pm

    Is this it?

     NAME        popen, pclose - process I/O  SYNOPSIS        #include <stdio.h>           FILE *popen(const char *command, const char *type);         int pclose(FILE *stream);  DESCRIPTION        The  popen()  function opens a process by creating a pipe, forking,  and invoking the shell.  Since a pipe is by definition unidirectional, the  type argument may specify only reading or writing, not both; the resulting  stream is correspondingly read-only or write-only.         The command argument is a pointer to a null-terminated string  containing a shell command line.  This command is passed to /bin/sh  using the -c flag; interpretation, if any, is performed by the shell.   The type argument is a pointer to a null-terminated string which must be  either ‘r’ for reading or ‘w’ for writing.         The  return  value  from popen() is a normal standard I/O stream in  all respects save that it must be closed with pclose() rather than fclose().   Writing to such a stream writes to the standard input of the command; the  command’s standard output is the same as that of the process that called  popen(), unless this is altered by the command itself.  Conversely, reading  from a ‘‘popened’’ stream reads the command’s standard output, and the  command’s standard input is the same as that of the process that called  popen().         Note that output popen() streams are fully buffered by default.         The pclose() function waits for the associated process to terminate  and returns the exit status of the command as returned by wait4(). 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 155k
  • Answers 155k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Ya, finally I got this web.xml after lots of reading… May 12, 2026 at 10:37 am
  • Editorial Team
    Editorial Team added an answer Have you taken a look at the Actual Execution Plans.… May 12, 2026 at 10:36 am
  • Editorial Team
    Editorial Team added an answer The problem is with the string "C:\Users\Eric\Desktop\beeline.txt" Here, \U in… May 12, 2026 at 10:36 am

Related Questions

I'm starting a small/medium-sized python project, likely in Test Driven Development. My backgrounds are
I am developing a scientific application used to perform physical simulations. The algorithms used
I have a list/queue of 200 commands that I need to run in a
Does anyone know, or have a link to an article or a step by

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.