-1

Some context: I am trying to access a router from a java program and I want to access it via a web browser. The easiest way I can think of is sending a command to the command-line, but none of the code that I have been using has worked thus far.

the method that I'm using is:

    Runtime.getRuntime.exec(); 

I'm not sure what command I should enter. Any suggestions?

Edit: I forgot to mention that I need a Mac and Windows version.

  • 1
    Regarding opening a web browser this might be interesting (it isn't command line but does open a browser); [Getting java gui to open a webpage in web browser](http://stackoverflow.com/questions/602032/getting-java-gui-to-open-a-webpage-in-web-browser). What you want to do after that is less clear – Richard Tingle May 20 '14 at 16:44

4 Answers4

0

That command will take command line arguments. The arguments depend on the operating system you're running on. This is one of those questions where the answer is "it depends".

See this question for some background info.

Kyte
  • 834
  • 2
  • 12
  • 27
0

If all you have to do is open a browser you can do

Runtime  rt = Runtime.getRuntime();
rt.exec("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe google.com");
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
0

Not sure I understood the question well, but if it is : "How do we execute a command from a Java program" here is an example :

public void execCmd()
{
    ProcessBuilder pB = new ProcessBuilder("copy file1 file2");
    Process p = pB.start();
}
Hybris95
  • 2,286
  • 2
  • 16
  • 33
0

The AWT Desktop#browse method will open a given URL in the current user's default browser in a cross-platform manner:

import java.awt.Desktop;
import java.net.URI;

...

Desktop.getDesktop().browse(new URI("http://whatever/"));

This of course requires that your Java program be running in an interactive session.

nobody
  • 19,814
  • 17
  • 56
  • 77