简体   繁体   中英

Java Runtime.getRuntime().exec

When I run this in my Windows command prompt it opens the default browser and loads the respective page:

START: http://google.com

I am trying to do the same thing with the Java code below but get an error message.

Runtime.getRuntime().exec(new String[] {"START", "http://google.com"});

This is the error I am getting:

Exception in thread "main" java.io.IOException: Cannot run program "START": 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 Test2.main(Test2.java:78)

I am running Windows Vista.

I believe that START is a command prompt builtin rather than an executable file, so you can't call it from Java. If you want to view a webpage with the system's default browser, use java.awt.Desktop.browse() .

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