0

I have a issue for this code . Please help me review :

Runtime.getRuntime().exec("cmd.exe /c start chrome " + url);

This code is OK if I launch the url which does not contain parameter, but i put parameter to this url,the link does not work and dont see parameter on url. thanks

2
  • 3
    Paste the url that is causing the problem. I think the problem may be due to not escaping back slashes. Commented Apr 25, 2015 at 7:29
  • This url runs on local. Example : 127.0.0.1/acb/display.do?user=abc&password=123 Commented Apr 25, 2015 at 8:18

3 Answers 3

3

Use this:

Desktop.getDesktop.browse(uri);
Sign up to request clarification or add additional context in comments.

1 Comment

This code uses for default browser.I want to launch url on multiple browser. Thanks.
2

Try this:

Runtime.getRuntime().exec("cmd.exe /c start chrome \"" + url + "\"");

Comments

0

The url contains various symbols that cmd may think illegal to use. For example

 cd new folder

is illegal as there is a space between so u must use

cd "new folder"

Just the same you must enclose the url in "" to make it work. Thus you must use:

Runtime.getRuntime().exec("cmd.exe /c start chrome \"" + url + "\"");

Or use this to directly launch the url in default browser:

Desktop.getDesktop.browse(uri);

Note wherever there is a \ in the url you must use \\ in place of it. So that java doesnot mistakes it as an escape sequence.

1 Comment

"So wherever there is a / in the url you must use // in place of it." No, that is only the case for back-slash (\).

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.