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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:42:09+00:00 2026-06-06T07:42:09+00:00

Is it possible to send data to another C++ program, without being able to

  • 0

Is it possible to send data to another C++ program, without being able to modify the other program (since a few people seem to be missing this important restriction)? If so, how would you do it? My current method involves creating a temporary file and starting the other program with the filename as a parameter. The only problem is that this leaves a bunch of temporary files laying around to clean up later, which is not wanted.

Edit: Also, boost is not an option.

  • 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-06T07:42:10+00:00Added an answer on June 6, 2026 at 7:42 am

    Clearly, building a pipe to stdin is the way to go, if the 2nd program supports it. As Fred mentioned in a comment, many programs read stdin if either there is no named file provided, or if - is used as the filename.

    If it must take a filename, and you are using Linux, then try this: create a pipe, and pass /dev/fd/<fd-number> or /proc/self/fd/<fd-number> on the command line.

    By way of example, here is hello-world 2.0:

    #include <string>
    #include <sstream>
    #include <cstdlib>
    #include <cstdio>
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/wait.h>
    
    int main () {
    
      int pfd[2];
      int rc;
    
      if( pipe(pfd) < 0 ) {
        perror("pipe");
        return 1;
      }
    
      switch(fork()) {
      case -1: // Error
        perror("fork");
        return 1;
    
      case 0: { // Child
        // Close the writing end of the pipe
        close(pfd[1]);
    
        // Create a filename that refers to reading end of pipe
        std::ostringstream path;
        path << "/proc/self/fd/" << pfd[0];
    
        // Invoke the subject program. "cat" will do nicely.
        execlp("/bin/cat", "cat", path.str().c_str(), (char*)0);
    
        // If we got here, then something went wrong, then execlp failed
        perror("exec");
        return 1;
      }
    
      default: // Parent
        // Close the reading end.
        close(pfd[0]);
    
        // Write to the pipe. Since "cat" is on the other end, expect to
        // see "Hello, world" on your screen.
        if (write(pfd[1], "Hello, world\n", 13) != 13)
          perror("write");
    
        // Signal "cat" that we are done writing
        close(pfd[1]);
    
        // Wait for "cat" to finish its business
        if( wait(0) < 0)
          perror("wait");
    
        // Everything's okay
        return 0;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to send data within a WLAN as fast as possible to another
Is it possible to send data from app engine server to another,external server with
It is possible to send POST data from JQUery to server, located in another
Is it possible to connect to remote host with indy client and send data
Is it possible to send mail in core php via gmail smtp without using
Is it possible to send a selector to another class and have it perform
It's possible via .htaccess send query to another file? A bit explaining: index.php handle
Is it possible to submit another parameter outside the form data in rails? My
Is it possible to send AJAX data with params, that aren't in the URL?
Possible Duplicate: Call controller's function from another controller / Share data between controllers I

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.