This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Accessing fifo pipes from windows programs


Hello,
I have some problems accessing a fifo file from my Java program. Fifos work correctly with cygwin tools, example:


 $ mkfifo fifo
 $ echo 'hello' >> fifo
This blocks. In another shell, I do:
 $ cat fifo
 hello
So this works fine. It unblocks the echo and writes the "hello".

Now trying the same thing with my java app:
 $ mkfifo fifo
 $ ls -l
 total 1
 prw-rw-rw- 1 Phil Aucun 0 Apr 17 12:58 fifo

Starting the producer (code at end of post):
$ java -cp .. DateWriter fifo
Fri Apr 17 13:02:20 CEST 2009
Fri Apr 17 13:02:21 CEST 2009
[...]
It does not block but writes into a second file instead
$ ls -l
total 2
-rwxr-xr-x 1 Phil Aucun 120 Apr 17 13:02 fifo
-rwxr-xr-x 1 Phil Aucun 120 Apr 17 13:02 fifo
Two files with the same name... The last-modif date of the original fifo is modified, but the content is in the first. When viewed with Windows explorer, one is a shortcut (with comment :\0:fc:11b6) and the other a pure text file.


How can I access the named pipe correctly from my Java program? Correctly means, that writing in the Java blocks while nobody is listening.
Thanks for your answers.
Phil


Full Java code of producer:

import java.io.File;
import java.io.FileWriter;
import java.util.Date;
public class DateWriter {
   public static void main(String[] args) throws Exception{
       File fifo = new File(args[0]);
       FileWriter writer = new FileWriter(fifo);
       while(true){
           String toWrite = new Date() + "\n";
           System.out.print(toWrite);
           writer.write(toWrite);
           writer.flush();
           Thread.sleep(1000);
       }
   }
}




-- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]