简体   繁体   中英

Execute batch file from Java code

I tried to run the batch file from java code, bat file is running but in bat file internally it is calling proxyServer.js file.This .js file is not running. Below is the sample code.

try {
    String path="cmd /c start C:\\AxoneES_Viewers_Integration-2016Q3-SNAPSHOT_201609021003\\AxoneViewers.bat";

    Runtime rn=Runtime.getRuntime();
    Process pr=rn.exec(path);

} catch(IOException ex) {
         System.out.println("Exception Found");
}

As i mentioned internally it is calling .js file where they declared path of the .js file, below is the code , which declared the path. cd viewers\\apps\\maxq\\ node proxyServer.js

while running the bat file it is not able to find the path of .js file and it not running.

Can you help me is there any approach to execute the bat file from java.

Try editing the batch file to use absolute file names instead of relative file names. You mentioned your batch file has the lines

cd viewers\apps\maxq\
node proxyServer.js

Change the first line to something like C:\\full\\path\\to\\viewers\\apps\\maxq\\ . Check out this answer for the difference between absolute and relative file names.

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