This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

pipe data through stdout in windows.  RSS feed

 
Chris Stones
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have been googleing all day and this is driving me mad!!!
program2 processes data from program1 in the usual *nix way.

program1 < input.bin | program2 > output.bin

no problem in Unix.
in win32, stdin / stdout are not binary, but foratted text, ( replaces \n with \r\n etc etc ANNOYING )

in c, i would normally use freopen in win32 to set stdin / stdout to binary mode.

How can i accumplish this in java ?

I am using System.out and System.in to read / write serializable objects.
XML serialization is not optional, as i dont want to make my objects beans compliant, and i dont want to intorduce xstream as a dependancy... also performance is quite important, so binary serialisation is the way to go.

Is this possible ???

THANKS.

 
Carey Brown
Saloon Keeper
Posts: 2840
43
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting question. I'm curious to see other responses you get. Off hand I'd say to use base64 encoding, that would eliminate the carriage-return issue and the object IO issue but does have some performance hit. Also program 1 & 2 would have to agree to talk using this format. There are lots of base64 java libraries out there, Apache.Commons has one.
 
Chris Stones
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
confused!!!

decided to *just try it anyway(tm)*
and everyhing seems to be working fine !

perhaps sun anticipated my needs, and implemented the binary serialization algorithm to work around
win32 annoyances, or perhaps the vm sets stdin / stdout binary on startup.

not sure how this is working, but it is !
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There ya go... the answer to "Will this work?" is generally "What happened when you tried it?". Especially when it costs very little to try it. Thanks for the feedback, it might be useful for someone else in the future.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!