aspose file tools*
The moose likes Java in General and the fly likes Executing commands from a java file with the help of processBuilder class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Executing commands from a java file with the help of processBuilder class" Watch "Executing commands from a java file with the help of processBuilder class" New topic
Author

Executing commands from a java file with the help of processBuilder class

Roneet Shaw
Greenhorn

Joined: Feb 14, 2014
Posts: 3
I want to run the following command from a java file
command : "java hello < C:\iptest\input.txt > C:\outtest\name.txt"
hello will take input from "C:\iptest\input.txt" and will produce an output file at "C:\outtest\name.txt".
codes i have done

String command[]={"java","hello","< C:\\iptest\\input.txt >","C:\outtest\name.txt"};
ProcessBuilder pb=new ProcessBuilder(command);
pb.directory(new File("E:\"));
now how to redirect input and output files i have no idea .Please Help!!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18168
    
    8

Welcome to the Ranch, Roneet!

As for how to redirect input and output for a ProcessBuilder, why not check out its API documentation? There's an example there which shows you how.
Roneet Shaw
Greenhorn

Joined: Feb 14, 2014
Posts: 3
can you please help me with the code .I have gone through the documentation but it has not helped me
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18168
    
    8

Sure. Let's see the new code you have based on the example from the documentation.
Roneet Shaw
Greenhorn

Joined: Feb 14, 2014
Posts: 3
I am building an application which can compile programs written on different languages . So here what do i have to do next ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
Do you have a grammar for those languages?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Executing commands from a java file with the help of processBuilder class
 
Similar Threads
StringTokenizer and flags
input data for external program
Writing java wrapper class
Input redirection in Java
GUI update.