简体   繁体   中英

Running batch file in java

I am trying to run a batch file using java. The batch file in turn runs a python program. So i should wait till the batch file is done and then proceed with my program.

Problems facing:

  1. I could not run batch file in background. I am able to run it only via start

    Process p = Runtime.getRuntime().exec("cmd /c start c://GCTI//IA/QAART//testercheck.bat");

  2. once the batch file ran, it is not closing automatically.

Batch file

"C:\Python27\python.exe" -i "C:\GCTI\IA\QAART\tester\test_monitor.py" -init "C:\GCTI\IA\EpiPhone\Dispatcher6\init\INIT_Designer_QAART_Dispatcher_Chat.PY" -testlist "C:\GCTI\IA\ASR_QAART\dat files\ChatAutomation\chat.dat" 23

Can you please help me to run this batch ile in background?

You don't need the batch file. You can execute the Python program directly from Java code using class java.lang.ProcessBuilder .

ProcessBuilder pb = new ProcessBuilder("C:\\Python27\\python.exe",
                                       "-i",
                                       "C:\\GCTI\\IA\QAART\\tester\\test_monitor.py",
                                       "-init",
                                       "C:\\GCTI\\IA\\EpiPhone\\Dispatcher6\\init\\INIT_Designer_QAART_Dispatcher_Chat.PY",
                                       "-testlist",
                                       "C:\\GCTI\\IA\\ASR_QAART\\dat files\\ChatAutomation\\chat.dat",
                                       "23");
Process p = pb.start();
int result = p.waitFor();

Refer to other methods in class ProcessBuilder for handling the output of the Python script, for example method inheritIO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM