Kevin
Kevin

Reputation: 6833

a question related to Google Translate

it works perfectly fine if I paste the following URL directly into my IE address bar:

http://translate.google.cn/translate?hl=zh-CN&sl=zh-CN&tl=en&u=http%3A%2F%2Fnews.baidu.com%2Fns%3Fword%3D%25B0%25C2%25B0%25CD%25C2%25ED

it will translate some Chinese news pages into English ones.

but if I call this address in a Java program like:

Process q=Runtime.getRuntime().exec(
  "cmd /c start http://translate.google.cn/translate?hl=zh-CN&sl=zh-CN&tl=en&u=http%3A%2F%2Fnews.baidu.com%2Fns%3Fword%3D%25B0%25C2%25B0%25CD%25C2%25ED"); 

It will only return to the Google translate main page.

Wonder what went wrong there.

and it would be great if you help me how to realize this(opening the Google translated result page simplying by supplying the URL,in a Java program).

Many thanks.

Upvotes: 0

Views: 293

Answers (3)

Oskar Kjellin
Oskar Kjellin

Reputation: 21870

I would say that it because it is framed. Try right clicking the translated page and get the URL that way

Upvotes: 1

Joey
Joey

Reputation: 354456

The & character is a special character for the shell. Try quoting the argument instead:

Process q=Runtime.getRuntime().exec(
    "cmd /c start \"\" \"http://translate.google.cn/translate?hl=zh-CN&sl=zh-CN&tl=en&u=http%3A%2F%2Fnews.baidu.com%2Fns%3Fword%3D%25B0%25C2%25B0%25CD%25C2%25ED\"");

Note the empty quotes in front of the argument; they are necessary for start.

By the way, you can easily try out whether your command line works at all by copying it into the command line and watching the result. In your case it produced the following:

H:>cmd /c start http://translate.google.cn/translate?hl=zh-CN&sl=zh-CN&tl=en&u=http%3A%2F%2Fnews.baidu.com%2Fns%3Fword%3D%25B0%25C2%25B0%25CD%25C2%25ED
'sl' is not recognized as an internal or external command,
operable program or batch file.
'tl' is not recognized as an internal or external command,
operable program or batch file.
'u' is not recognized as an internal or external command,
operable program or batch file.

which gives pretty good clues about what goes wrong here.

However, if you are on Java 6 you can also use the browse method of the Desktop class. This has the benefit of working on other systems than Windows as well.

Upvotes: 4

schar
schar

Reputation: 2658

My guess is : Google might be checking to see the user agent. They would do it to discourage automated programs and any DOS attacks.

Upvotes: 0

Related Questions