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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:26:03+00:00 2026-06-09T03:26:03+00:00

This is just a small part of a bigger program but Im trying to

  • 0

This is just a small part of a bigger program but Im trying to get the output from execvp
I have execvp set up correctly with dup2 that directs it into a pipe.
My problem comes when it comes to using read to read the full length of the pipe I don’t know how large the output of execvp is each time cause it can be different depending on the input.

    int fd[2];
    pipe(fd);
    pid_t pid = fork();
    if (pid == 0) {
        close(fd[0]);
        dup2(fd[1], 1);
        execvp(msg.v,(char *[]){msg.v,NULL});
    } else if (pid > 0) {
        close(fd[1]);
        read(fd[0],msg.v,....);
    }

I have tried a few different sizes for read but its either not enough or I end up getting random junk at the end I know you can use popen and a few other things from stdio but its required for the assignment that we do not use them Im blanking on other ways to go about getting the output.

A little more useless info the whole program is part of a server. Im making a server and a client.. start the server give the client a terminal command it sends it over to the server over a INET stream and sending the output back to the client to display output all without stdio.

  • 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-09T03:26:05+00:00Added an answer on June 9, 2026 at 3:26 am

    You have to pay attention to how much data read returns into your buffer. While read is returning positive numbers, you have more data. When the program is done, it will close its end of the pipe, and your read will return 0.

    } else if (pid > 0) {
        close(fd[1]);
        ssize_t r = read(fd[0],buf,bufsz);
        if (r > 0) do {
            /* ... do something with r bytes in buf */
            r = read(fd[0],buf,bufsz);
        } while (r > 0);
        if (r < 0) {
            perror("read");
            /*...*/
        }
    }
    

    If you see read give an “Interrupted system call” error, then you have encountered the EINTR case that caf mentioned. You restart your read again in that case.

            for (;;) {
                r = read(fd[0],buf,bufsz);
                if (r != -1 || errno != EINTR) break;
            }
    

    I am assuming you are not doing non-blocking I/O, so you will not encounter the “Resource temporarily unavailable” message.

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

Sidebar

Related Questions

So this is a small part of a large assignment I have, I'm just
I'm learning JavaFX and this is just a small programming question. I have 3
I fear this just may not be possible, but I'm trying to create a
I'm trying to learn C to program this small routine on a Texas Instruments
I just want to get a BitmapImage from a internet URL, but my function
Okay, before you guys go nuts -- this is just a small site, temporary
This just saves time. Since I already have a web applciation. I can just
So for some reason this just doesn't make sense to me. What Im trying
I understand this is an easy question but for some reason this just isn't
I don't think that this could be done in C#, but posting this just

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.