Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ProcessBuilder Constructor

 
Shraddha Pandya
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All
File directory = new File("C:\\");
List<String> list = new ArrayList<String>();
list.add("cmd");
list.add("test.bat");
list.add( "/C");
ProcessBuilder pb = new ProcessBuilder(list);
// ProcessBuilder pb = new ProcessBuilder("cmd","/C","test.bat");
pb.directory(directory.getAbsoluteFile());
Process p = pb.start();
pb.redirectErrorStream(true);

BufferedReader bfr = new BufferedReader(new InputStreamReader(p.getInputStream()));

while ((line = bfr.readLine()) != null)
{
System.out.println(line);
}
r.close();

If am executing batch file using list [ProcessBuilder pb = new ProcessBuilder(list);], am not seeing any output here but ProcessBuilder pb = new ProcessBuilder("cmd","/C","test.bat"); yields output.
Can someone please explain what wrong is with the first constructor?

Thanks
Shraddha

 
Rob Spoor
Sheriff
Pie
Posts: 20510
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the order of your List elements.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic