1
public class test2 { public static void main(String[] args) { try { // print a message System.out.println("Executing VLC.exe"); Process process = Runtime.getRuntime().exec("C:\\Program Files\\VideoLAN\\VLC\\vlc.exe"); // print another message System.out.println("VLC should now open."); } catch (Exception ex) { ex.printStackTrace(); } } } 

Here is the error:

Cannot run program "C:\Program": CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(Unknown Source) at java.lang.Runtime.exec(Unknown Source) at java.lang.Runtime.exec(Unknown Source) at java.lang.Runtime.exec(Unknown Source) at test2.main(test2.java:21) Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessImpl.create(Native Method) at java.lang.ProcessImpl.<init>(Unknown Source) at java.lang.ProcessImpl.start(Unknown Source) ... 5 more*** 

But this program runs notepad.exe and associated text files rather easily. So can it only run programs in Win32?

2 Answers 2

2

enter image description here

here is the pic with the dos ...

Sign up to request clarification or add additional context in comments.

3 Comments

how about running cmd /c start "C:\Program Files\VideoLAN\VLC\vlc.exe" and cmd /c start C:\Program^ Files\VideoLAN\VLC\vlc.exe in cmd?
Actually, a command like cmd /c start C:\"Program Files"\VideoLAN\VLC\vlc.exe has to work. The double quotations force escaping the white space in "Program Files". Tested just now!
but i got it working by appending the original one to new String[]{ "C:\\Program Files\\VideoLAN\\VLC\\vlc.exe","\""}
1

This problem is because of the white space in "Program Files".

You can avoid any problems like this by using the Runtime#exec that takes a String[]:

Runtime.getRuntime().exec(new String[] {"cmd", "/c", "start", "C:\Program Files\VideoLAN\VLC\vlc.exe"}); 

That way you don't have to worry about quoting the file names. However, you still have to worry about quoting \ in the file names.

4 Comments

"cmd", "/c", "start" what is the purpose of this?
and eclipse is still giving me the invalid sequence character error
after i changed it back to "\\" , it opened a new dos window with the directory as my byte code directory
try cmd /c start C:\Program Files\VideoLAN\VLC\vlc.exe in cmd and tell me what's the output, first.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.