LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-19-2007, 03:28 PM   #1
the_7th_world
LQ Newbie
 
Registered: Aug 2004
Posts: 12

Rep: Reputation: 0
Writing to a named pipe in Java


Hi everyone,

I was hoping some of you might be able to give me a bit of advice on a coding problem I've been battling with for the last while.

I have been given a program which I run as root:

# ./prog pipe1 &

An argument of the program was a named pipe that I had earlier created with:

$ mknod pipe1 p

From the command line, to get the program to do it's stuff, I do the following:

$ echo "DO SOMETHING" > pipe

When I do this, the program functions perfectly and does as expected.

In a thread of a program that I am writing in Java, I need to send this string to the pipe that the program is using.

I have tried everything that I can think of - running the above command as a new process from within Java, creating a PrintWriter to write to the pipe as if it were a file and many others.

Would anyone have any thoughts on the way to 'echo' information into this pipe?

All advice will be much appreciated.

Thanks,
7th

P.S.

I hope I have explained the problem well. Any questions, please don't hesitate to ask
 
Old 11-19-2007, 05:40 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Just treat it like any other file...

Hi -

There's really no "magic":

1. On Linux, you want to use the "mkfifo" command (not "mknod")

2. To write to it from Java, just open some kind of OutputStream to that filename (exactly as you would, for example, open a text file).

3. That's it!

Here's a link that might give some more info:
http://developers.sun.com/solaris/ar...med_pipes.html

'Hope that helps .. PSM
 
Old 11-21-2007, 02:25 AM   #3
Alien_Hominid
Senior Member
 
Registered: Oct 2005
Location: Lithuania
Distribution: Hybrid
Posts: 2,247

Rep: Reputation: 53
mknod pipe p works (or should work) the same way as mkfifo pipe
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
syslog not writing to named pipe (fc4) darbo Linux - Software 0 02-17-2006 07:35 PM
What is a named pipe ronzoid Linux - General 1 01-18-2006 04:30 PM
unlinking named pipe sahel Programming 1 01-12-2006 04:45 AM
unlinking named pipe sahel Programming 1 01-09-2006 10:36 PM
named pipe sahel Programming 1 01-09-2006 08:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration