简体   繁体   中英

Runtime.exec Error but works in cmd line

I am using the following very simple code to open outlook using the cmd line:

Start OUTLOOK.EXE

When I type it into the Windows Command Processor it works fine but when I use:

Runtime.exec(String[]{"Start ", "OUTLOOK.EXE"}); 

or

Runtime.exec("Start OUTLOOK.EXE);

or

Runtime.exec(String[]{"Start", " ", "OUTLOOK.EXE"});

In java it does not work (I get this error: Cannot run program "Start": CreateProcess error=2, The system cannot find the file specified) why ? I have read about spaces and runtime but I cannot get it working.

Thanks Ulrich


Ok so with some more googling I got it working:

Runtime.getRuntime().exec("cmd.exe /c start OUTLOOK.EXE");

That will open it, I hope people find this because I have been searching for some hours trying to figure out how to open a program I do not know the file path to.

Do not use "start". Just having outlook.exe is enough.

Runtime.exec("OUTLOOK.EXE");

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