# Transfering data between two programs



## crucifix (May 15, 2014)

Hi
Do you know how I can transfer data between the two programs in C++?
Shell:

```
chmod +x program1
chmod +x program2
program1 | program2
```


```
char data = "q";
```
In code program1:

```
cout << data;
```
In code program2:

```
cin >> data;
```
Is this the way will be sent to a variable of type char ?


----------



## SirDice (May 15, 2014)

It's called InterProcess Communication or IPC for short. And there are various techniques you can use to achive it. The developer's handbook shows how to do this using sockets. But it can also be done with (temporary) files or by using shared memory. 

Developers Handbook: Part II. Interprocess Communication


----------



## crucifix (May 15, 2014)

I want to transfer data between the two programs using the stream.
How do I program in C?


----------



## freethread (May 15, 2014)

In C++, Boost has a good library for IPC: http://www.boost.org/doc/libs/1_55_0/doc/html/interprocess.html. In C one method is to use memory mapped files, see mmap(), but as @SirDice said, there are many techniques. Anyhow, reading the Boost.Interprocess documentation you can learn about some of those techniques.


----------



## crucifix (May 15, 2014)

Try it. May allowed the transfers in between two active processes  Thanks


----------



## ghii (May 18, 2014)

crucifix said:
			
		

> Hi
> Do you know how I can transfer data between the two programs in C++?
> Shell:
> 
> ...




I think it's OK as std::cout and std::cin have the same effect with echo and read. Pipe can be used for both.


----------



## worldi (May 21, 2014)

If one is interested in interprocess communications I'd highly recommend getting a copy of Mr. Stevens' UNIX Network Programming, Volume 2.


----------

