Frage

I am trying to execute an .exe file(Say abc.exe) which I would execute from command line as:

C:\....pathtoExe>abc.exe /m param1

The code is:

                String cmd[]={"bin/ocr/abc.exe","/m",param1};
                Process p = Runtime.getRuntime().exec(cmd);
                p.waitFor();

Pls note that the bin/ocr/abc.exe is the relative path of the exe file and is correct one. Hoewver when I get the input stream and try to read it, I dont get the desired output(Infact I dont get any output at all as inputStream returns nothing). I also have a batch file in the same directory(run.bat) with the following code:

abc.exe /m %1 > abc_out.txt

This can be executed from command prompt as:

C:\...pathtobat>run.bat param1

So how do I execute above batch file which takes a parameter from command prompt? My main aim is to run the .exe file properly from java and get the output returned from the .exe file.

Keine korrekte Lösung

Andere Tipps

This should work:

String cmd[]= { "abc.exe", "/c", param1 };
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top