0

Below is the exception thrown when trying to open a create new email for outlook.

Exception :

java.io.IOException: Cannot run program "C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE /c ipm.note": CreateProcess error=2, The system cannot find the file specified

Exception occurs at first line of below code snippet :

ProcessBuilder processBuilder = new ProcessBuilder("C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\OUTLOOK.EXE /c ipm.note");
            try {
                processBuilder.start();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

When I donot specify the switch /c ipm.note the code works fine and a new outlook window opens up. But with the switch I get exception. Not sure what's the reason.

I referred following stackoverflow post : https://stackoverflow.com/a/6045897/2915738 and the related site : https://www.outlook-tips.net/how-to/using-outlook-command-lines/

Please guide me. Let me know if you need some more info.

Asif Kamran Malick
  • 2,409
  • 3
  • 25
  • 47
  • If you execute the command in command prompt , are you able to see any error ? – Sambit May 15 '19 at 06:56
  • @Sambit Just tried it. I do not get any error when I run it via cmd. It successfully opens up the new email window. – Asif Kamran Malick May 15 '19 at 07:03
  • Can you provide the stacktrace details ? It will give more insight into the problem. Sometime if there is a space like string for accessing files and folder, it gives problem in Windows. Can you try like this . "\""+"C:\\Program Files (x86)"+"\""+File.separator+Microsoft Office+File.separator+"root"+File.separator+"Office16" like this. – Sambit May 15 '19 at 07:10
  • @Sambit Thanks for your help. Minus' solution worked for me. I missed the arguments. – Asif Kamran Malick May 15 '19 at 07:33

1 Answers1

1

You should split arguments, otherwise it won't work as expected:

ProcessBuilder processBuilder = new ProcessBuilder(
  "C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\OUTLOOK.EXE",
  "/c", "ipm.note");
minus
  • 2,646
  • 15
  • 18