aspose file tools*
The moose likes Java in General and the fly likes ProcessBuilder Constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ProcessBuilder Constructor" Watch "ProcessBuilder Constructor" New topic
Author

ProcessBuilder Constructor

Shraddha Pandya
Greenhorn

Joined: Sep 20, 2004
Posts: 17
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


SCBCD(EJB2.0)
SCJP(1.4)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Check the order of your List elements.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: ProcessBuilder Constructor