• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pipe between Java and C processes?

 
Cristian Vrabie
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9319
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Cristian Vrabie
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
I will try the solution for named pipes outside VM and post my findings.
 
Samuel March
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On one side put




getInputStream() .. MyInputStreamClassExtension : extend class InputStream or anything that extends it.
 
Cristian Vrabie
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic