| Terminate paused console output of a batch file called as external tool [message #326929] | 
Thu, 03 April 2008 06:50   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Originally posted by: ups_genius.gmx.net 
 
Hi everyone! 
 
I am calling batch files via the External Tools option and parse the  
output written to console with implementing IPatternMatchListenerDelegate. 
 
Everything works fine until there is a "pause" command in the batch file.  
The console output of course is paused and continues only when pressing  
enter within the console window. In my case this is pretty annoying,  
because the pause command is located at the end of a lot of batch files  
used for building my project. 
 
Unfortunately I cannot modify the batch files, so I tried to add another  
IPatternMatchListenerDelegate listening to the command issued when the  
pause command is reached ("Press any button to continue ..." or something  
like that). I planned in this case to simply write "\r\n" to the very same  
console, but am actually having problems with it. 
 
I tried the following: 
 
ConsolePlugin plugin = ConsolePlugin.getDefault(); 
IConsoleManager conMan = plugin.getConsoleManager(); 
conMan.addConsoles(new IConsole[] { console }); 
 
final IDocument doc = console.getDocument(); 
 
Display.getDefault().syncExec( 
  new Runnable() { 
    public void run(){ 
      doc.set("\r\n"); 
 } 
}); 
 
 
 
The problem is, that this only writes to the console, and does not append  
the required string. Rewriting the whole console plus the new string also  
does not work since the IPatternMatchListenerDelegate is then invoked  
again. 
 
Can anyone help? Is there maybe an easier approach? 
 
Thanks in advance! 
Christian
 |  
 |  
  | 
| Re: Terminate paused console output of a batch file called as external tool [message #327031 is a reply to message #326929] | 
Mon, 07 April 2008 07:50   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Originally posted by: ChristianOpitz.gmx.net 
 
I found a solution, and it was easier than I expected: 
1. Use the org.eclipse.ui.console.consolePatternMatchListeners extension  
point to create a listener using the regex "Sie eine beliebige Taste|press  
any key to continue|nyomjon meg egy billentyut". I used the output of the  
pause command in different languages (there is probably a neater way to  
determine it, but this works for me) 
 
2. Use the following code in the matchFound method: 
 
    public void matchFound(PatternMatchEvent event) { 
 
        final IDocument doc = console.getDocument(); 
        Display.getDefault().syncExec(new Runnable() { 
            public void run() { 
                try { 
                    // Append the newline 
                    doc.replace(doc.getLength(), 0, "\r\n"); 
                } catch (BadLocationException e) { 
                    e.printStackTrace(); 
                } 
            } 
        }); 
    } 
 
 
Thats it!
 |  
 |  
  | 
Powered by 
FUDForum. Page generated in 0.03292 seconds