简体   繁体   中英

How to run .exe file using servlet

i want to run .exe file from local server. here is below code :

   String cmds = "C:\\IBM\\Abhishek\\Notepad++\notepad++.exe";
 try {
     Process p = Runtime.getRuntime().exec(cmds);
     System.out.println("process "+p);
     p.waitFor();

     BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
     String line = reader.readLine();
     System.out.println("Line---"+line);
     while (line != null) {
       System.out.println("File---"+line);
       line = reader.readLine();
     }
    } catch (Exception e) {
        System.out.println(" Sample Exception :"+e.getMessage());
    }

Here output is getting :

Sample Exception :Cannot run program "C:\IBM\Abhishek\Notepad++": CreateProcess error=5, Access is denied.

Please suggest,

The error message says CreateProcess error=5, Access is denied. which implies your Java servlet's process doesn't have permissions to execute that program.

The cause, I think, is that you are missing an \\\\ in front of notepad++.exe . You need to escape all of the backslashes.

   "C:\\IBM\\Abhishek\\Notepad++\notepad++.exe"
-> "C:\\IBM\\Abhishek\\Notepad++\\notepad++.exe"

Error 5 means one of on the following reasons. Either the File is not accessible or the File is not executable.

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