Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Roneet Shaw
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21321
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you please help me with the code .I have gone through the documentation but it has not helped me
 
Paul Clapham
Sheriff
Posts: 21321
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. Let's see the new code you have based on the example from the documentation.
 
Roneet Shaw
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49789
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a grammar for those languages?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic