This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use redirection when using ProcessBuilder

 
Jack Bush
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am trying to run the following command using ProcessBuilder that runs perfectly on a Windows command prompt:



Below is the code that has partly work but has difficulty reading input and producing output files:



This code appears to have worked as it displayed all the warning messages in standard output. However, it could not direct the output XML format to C:\Temp\NewXMLFormat.xml. Instead, the following error messages were generated in the standard error output:

Error: Can't open "<"

Error: Can't open ">"

Error: Can't open "NewXMLFormat.xml"

Looks like I need to some how direct the OldHTMLFormat.html file to the ProcessBuilder and the same applies to NewXMLFormat.xml.

Any assistance would be very much appreciated.

Thanks,

Jack
 
Piet Verdriet
Ranch Hand
Posts: 266
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take note of Piet Verdriet's point; you ought to tell us when posting on multiple sites. Please also go to Sun and add a post saying "posted on JavaRanch at [url=http://saloon.javaranch.etc.etc.etc".]http://saloon.javaranch.etc.etc.etc".[/url]

[edit]Remove URL tags. CR[/edit]
[ July 14, 2008: Message edited by: Campbell Ritchie ]
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you combined the two Streams from the Process? You don't seem to be consuming the input Stream.
Why aren't you using Process#waitFor?
Why aren't you using separate Threads to drain the Streams?

The classic article by Daconta )here) might be 8 years old, but it is still very relevant. I trust you are familiar with it?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The stream redirects are evaluated by the command line, not by the executed program. See Listing 4.5 in the article that Campbell pointed you to.
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Piet Verdriet",

Please read your private messages regarding an important announcement.

Thank you.
 
Jack Bush
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My apologies for not informing you all on also posting the same question on another site.

I will let you know in the future.

Your assistance is invaluable to everyone.

Thanks for letting me know,

Jack

P.S. Anyhow, this question has been resolved on the other site.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic