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.

4
  • If you execute the command in command prompt , are you able to see any error ? Commented May 15, 2019 at 6: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. Commented May 15, 2019 at 7: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. Commented May 15, 2019 at 7:10
  • @Sambit Thanks for your help. Minus' solution worked for me. I missed the arguments. Commented May 15, 2019 at 7:33

1 Answer 1

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");
Sign up to request clarification or add additional context in comments.

1 Comment

This resolved my issue. I had not split the arguments. Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.