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

  • Home
  • SEARCH
  • 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 3698782
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:01:25+00:00 2026-05-19T05:01:25+00:00

can someone give me simple example in c, of using pipe() system call to

  • 0

can someone give me simple example in c, of using pipe() system call to and use ssh to connect to a remote server and execute a simple ls command and parse the reply. thanks in advance,..

  • 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-19T05:01:26+00:00Added an answer on May 19, 2026 at 5:01 am
    int main()
    {
        const char host[] = "foo.example.com";  // assume same username on remote
        enum { READ = 0, WRITE = 1 };
        int c, fd[2];
        FILE *childstdout;
    
        if (pipe(fd) == -1
         || (childstdout = fdopen(fd[READ], "r")) == NULL) {
            perror("pipe() or fdopen() failed");
            return 1;
        }
        switch (fork()) {
          case 0:  // child
            close(fd[READ]);
            if (dup2(fd[WRITE], STDOUT_FILENO) != -1)
                execlp("ssh", "ssh", host, "ls", NULL);
            _exit(1);
          case -1: // error
            perror("fork() failed");
            return 1;
        }
    
        close(fd[WRITE]);
        // write remote ls output to stdout;
        while ((c = getc(childstdout)) != EOF)
            putchar(c);
        if (ferror(childstdout)) {
            perror("I/O error");
            return 1;
        }
    }
    

    Note: the example doesn’t parse the output from ls, since no program should ever do that. It’s unreliable when filenames contain whitespace.

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

Sidebar

Related Questions

Can someone give an example of a good time to actually use unsafe and
When is it appropriate to use CoTaskMemAlloc? Can someone give an example?
Can someone give me a very simple example of how one would, say, write
Can someone give a simple example of updating a textfield every second or so?
Can someone give me some example code that creates a surface with a transparent
I`m really new in Objective-C and Mac OSX programming. Can someone give me simple
Can someone give some hints of how to delete the last n lines from
Guys, can someone give me a brief run through of how to change the
Title is the entire question. Can someone give me a reason why this happens?
I'm looking to learn Windows PowerShell. Can someone give me some really good references

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.