wood burning stoves*
The moose likes Java in General and the fly likes How to use redirection when using ProcessBuilder    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to use redirection when using ProcessBuilder    " Watch "How to use redirection when using ProcessBuilder    " New topic
Author

How to use redirection when using ProcessBuilder

Jack Bush
Ranch Hand

Joined: Oct 20, 2006
Posts: 235
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

Joined: Feb 25, 2006
Posts: 266
http://forum.java.sun.com/thread.jspa?threadID=5313572
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38483
    
  23
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

Joined: Oct 13, 2005
Posts: 38483
    
  23
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

Joined: Jul 11, 2001
Posts: 14112
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.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19680
    
  19

"Piet Verdriet",

Please read your private messages regarding an important announcement.

Thank you.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jack Bush
Ranch Hand

Joined: Oct 20, 2006
Posts: 235
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use redirection when using ProcessBuilder