0

I have some problems with execute .bat file. I used Spring Roo to generate web services from the command line and wanted to write a connector to the .bat file from java code. When I launch my application, it hangs tight, (it seems the current thread is switching to a .bat file). How can I configure support for the command exchange process between roo.bat(or another .bat file) and java code.

For example:
--> start roo.bat
--> answer: roo> 
--> send from java: project setup --topLevelPackage org.springframework.roo.example
ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "C://Users/Documents/roo/bin/roo.bat");
pb.redirectErrorStream(true);
Process proc = pb.start();
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);

String line;
int exit = -1;

while ((line = br.readLine()) != null) {
    // Outputs your process execution
    System.out.println(line);
    try {
        exit = proc.exitValue();
        if (exit == 0)  {
            // Process finished
        }
    } catch (IllegalThreadStateException t) {
            proc.destroy();
    }
}

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Michael
  • 11
  • 5
  • So, to be clear, you want to re-implement cgi-bin from a Java spring web application? This is not, in my opinion, a Good Idea. – Elliott Frisch Aug 04 '19 at 17:32
  • @ElliottFrisch No, I want my java code (this is not a web application) to be able to fully "communicate" with roo.bat (Spring roo) or another .bat file. Problem with messaging between .bat files and java application (roo.bat such as "example"). – Michael Aug 04 '19 at 18:43
  • You will need two more Java threads; one to read the values written by your external process and one to write values to your external process. This is not the design I would use for an intra-process communication solution. TCP sockets, zero-mq or nanomsg would be my preference. – Elliott Frisch Aug 04 '19 at 18:50
  • @ElliottFrisch yes, but I don’t understand how to connect the second process (which must be connected to the first to send messages), because the first process is already working (it launched the .bat file). For example ---> fist process InputStream.. from .bat file. --> second process OutputStream to .bat file. – Michael Aug 05 '19 at 05:07

0 Answers0