aspose file tools*
The moose likes I/O and Streams and the fly likes Pipe between Java and C processes? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Pipe between Java and C processes? " Watch "Pipe between Java and C processes? " New topic
Author

Pipe between Java and C processes?

Cristian Vrabie
Ranch Hand

Joined: Jul 09, 2008
Posts: 71
Hi everybody!
I never had the chance to use pipes in Java so I'm a newbie in this field. I know from C that pipes can be used to communicate between 2 separate processes.
When reading about this in Java I see two different definitions:
1. that a pipe can be used ONLY to communicate between threads in the same JVM.
2. a pipe can be used to communicate with another process as long as the pipe is not created by Java.
Which one is it? I would need this to communicate between a Java process and a C process.
Thanks!
Cristian
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

The Java Pipe classes are implemented in-memory, so they will only work within the same JVM:
Instead of streaming data to a file, a thread can stream it through a pipe to another thread. The first thread writes to the
pipe, and the second thread reads from the pipe. A pipe is neither a file nor a network connection, but a structure in memory that holds the data that is written until it is read.


Java Thread Programming by Paul Hyde page 141

It may be possible to use named pipes outside the VM (see here), but I've never seen anyone do it.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Cristian Vrabie
Ranch Hand

Joined: Jul 09, 2008
Posts: 71
Thanks!
I will try the solution for named pipes outside VM and post my findings.
Samuel March
Ranch Hand

Joined: Oct 28, 2009
Posts: 39
On one side put




getInputStream() .. MyInputStreamClassExtension : extend class InputStream or anything that extends it.

...did you have the fish?!............................ No.
Cristian Vrabie
Ranch Hand

Joined: Jul 09, 2008
Posts: 71
I managed to do this work by making the C program create the pipe, then opening it from Java as a normal file. Pretty easy actually.
 
wood burning stoves
 
subject: Pipe between Java and C processes?