| Running a batch file from Eclipse [message #330362] | 
Sat, 26 July 2008 13:18   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Originally posted by: nospam.nospam.com 
 
I need to programmatically run a batch file from my Eclise plug-in. The  
batch file starts a command line tool. When it is running I need to input  
a command and get the output - again programmatically. 
What's a good way to do this in Eclipse? 
 
I tried to use Java's: 
Runtime.getRuntime().exec(...); 
but nothing seems to work, no console appears. 
 
I also tried to create my own concole with: 
MessageConsole console = new MessageConsole("My Console", null); 
 ConsolePlugin.getDefault().getConsoleManager().addConsoles(n ew  
IConsole[]{console}); 
MessageConsoleStream stream = console.newMessageStream(); 
stream.println("Hello, world!"); 
 
But it seems this is just a text concole that will not help me run the  
batch file. 
 
The last thing I tried is to run my batch file as an External Tool. This  
works OK with: 
IOConsoleOutputStream stream = ((IOConsole) consoles[0]).newOutputStream(); 
stream.write("Hello, world!"); 
But the text is not treated as a command as if the user typed it (green  
color).  
 
Any way to get this to work?
 |  
 |  
  | 
 | 
| Re: Running a batch file from Eclipse [message #330371 is a reply to message #330362] | 
Sun, 27 July 2008 04:36    | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Have you tried to start the batch file with cmd.exe? 
 
Process p = Runtime.getRuntime().exec(new String[]{"cmd.exe", "/c", "test.bat"},  
null, null); 
 
You might have a look at Apache Ant's Execute class to get an idea of working  
with input and output streams on a Process. 
 
Regards, Alex 
 
W.F. schrieb am 26.07.2008 19:18: 
> I need to programmatically run a batch file from my Eclise plug-in. The  
> batch file starts a command line tool. When it is running I need to  
> input a command and get the output - again programmatically. 
> What's a good way to do this in Eclipse? 
>  
> I tried to use Java's: 
> Runtime.getRuntime().exec(...); 
> but nothing seems to work, no console appears. 
>  
> I also tried to create my own concole with: 
> MessageConsole console = new MessageConsole("My Console", null); 
>  ConsolePlugin.getDefault().getConsoleManager().addConsoles(n ew  
> IConsole[]{console}); 
> MessageConsoleStream stream = console.newMessageStream(); 
> stream.println("Hello, world!"); 
>  
> But it seems this is just a text concole that will not help me run the  
> batch file. 
>  
> The last thing I tried is to run my batch file as an External Tool. This  
> works OK with: 
> IOConsoleOutputStream stream = ((IOConsole) consoles[0]).newOutputStream(); 
> stream.write("Hello, world!"); 
> But the text is not treated as a command as if the user typed it (green  
> color). 
> Any way to get this to work? 
>
 |  
 |  
  | 
| Re: Running a batch file from Eclipse [message #330379 is a reply to message #330371] | 
Sun, 27 July 2008 14:01   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Originally posted by: nospam.nospam.com 
 
Thanks this seems to work, but printing to the console when the tool is  
running doesn't. Here's what I have: 
 
Runtime r = Runtime.getRuntime(); 
Process p = r.exec(new String[] {"cmd.exe", "/c", "start", "cli.bat"},  
null, new File("C:\\Dir1\\Dir2")); 
PrintWriter writer = new PrintWriter(p.getOutputStream()); 
writer.println("help"); 
writer.close(); 
 
Actually I think that using the External Tools console would be better.  
But I have the same problem with writing to it when the tool is running.
 |  
 |  
  | 
Powered by 
FUDForum. Page generated in 0.04897 seconds