Send data between console apps

Posted on 2005-04-16
Last Modified: 2010-04-15
I've got two instances of the same console application.

The first one creates some data (char * data) of some length. This data should be sent to the second program that'll process the data.


    CONSOLE 1          header|length|data       CONSOLE 2
    char* data;         ----------------------->    received_data = malloc(length*sizeof(char));
    int length;

I've tried using _pipe, but this seems not to work.

Note that the CONSOLE 2 will stay in wait mode until it receives a message with the correct header.

I'd like a solution that's a simple as possible, if possible without needing additional non standard libraries. Saving the data to the HDD is not an option.

All this should work under Linux, as well as under Windows (or at least, there should be an alternative for both).

Thanks in advance!
Question by:Evarest
    LVL 22

    Accepted Solution

    I'd use a TCP connection.  

    On a similar project, after messing around with pipes for days, and finding all kinds of glitches, I switched to a TCP connection, which worked first time, and works identically on all cptrs.

    LVL 45

    Assisted Solution

    I would second greg's recommendation ... use sockets ... They are far more easier to deal, more portable, etc. etc. than any other IPC mechanism

    However, for the kind of communication you mentioned, even pipes should suffice ... you do not necessarily have to implement them on your own ... you can start up your application by adding pipe from the shell while launching them

    my_app_1 | my_app_2

    will do what you are looking for and works on windows and Linux
    LVL 4

    Author Comment

    I'm sorry i left this so long, but i had quite a busy month...

    In the end, i used neither solution, as i only had to implement a skeleton app... However, i'll keep in mind this discussion for future use.

    Thanks again!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now