7

I need to pass information from a shell script (called from a linux based app) to a java application.

Named pipes are a pain because I can't start/stop either service without considering complex repercussions to the read/write ends of the pipes.

Sockets are tough because if the listening process is restarted there's no queuing mechanism, and simple implementations require new sockets be constantly created (else the shell script will get very complex with check-and-restart-socket, and queuing code).

I was recently reading about these System V/POSIX linux message queues. I'm running Fedora 12, and wonder if there's a good way to configure these message queues and interact with them from Java.

6
  • 1
    possible duplicate of Java Posix IPC Is there an API? Commented Jun 20, 2011 at 5:33
  • How do you intend to interact with them from a shell script? Commented Jun 20, 2011 at 5:34
  • 1
    It's easier to write a simple C wrapper to bind a shell script to a posix message queue than it is to bind to JNI... Commented Jun 20, 2011 at 5:34
  • 1
    @bdonlan: Your proposed dup is about POSIX, while this post includes SYSV as a possibility, so it's not really a dup. Commented Jun 20, 2011 at 5:37
  • 1
    I agree, it's a dup, I had not found the question noted by bdonlan, and my terminology wasn't quite correct yet. POSIX is what I want I think, and the answers on that message are very useful, I've voted to close as duplicate as well. Thanks! Commented Jun 20, 2011 at 5:41

1 Answer 1

3

You can't use them directly, you'd have to do some JNI wizardry to interface them together.

What problems are you having with Pipes? Java sees those as just generic files. I haven't used them extensively, but I didn't have any real problems with Pipes. The only detail there was the pipe reader needs to continually reopen the pipe if the producers can't keep up.

But if either side fails, the other side just blocks waiting for the other to recover.

You just have to be careful with buffer reads from the pipe. If you read from the pipe in to a buffer, and then fail, that data is lost.

Sign up to request clarification or add additional context in comments.

1 Comment

I ended up fighting the named pipes, they were a bit odd in that the entire input/output stream class will block on the constructor until the other end of the pipe is open, so you kind of have to work around this, and as you mentioned, carefully monitor for EOF and re-open. It took a bit of monkeying around to figure out the 3 or 4 quirks required to get it right, but I think I got them now, it just didn't seem elegant, and things were a bit counter-intuitive. Trying to get the script right was another big issue, cat, tee and other common utils act very oddly when the other end opens/closes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.