call lynx from jsp script

Posted by Piero on Stack Overflow See other posts from Stack Overflow or by Piero
Published on 2010-05-18T11:12:15Z Indexed on 2010/05/18 13:20 UTC
Read the original article Hit count: 339

Filed under:
|
|
|

Hi,

I have an execute(String cmd) in a jsp script that calls the exec method from the Runtime class.

It works when I call a local command, like a php script stored on the server. for example: /usr/bin/php /path/to/php/script arg1 arg2

So I guess my execute command is ok, since it is working with that.

Now when I try to call lynx, the text-based web browser, it does not work.

If I call it in a terminal, it works fine: /usr/bin/lynx -dump -accept_all_cookies 'http://www.someurl.net/?arg1=1&arg2=2'

But when I call this from my execute command, nothing happens...

Any idea why?

This is my execute method:

public String execute(String cmd){


        Runtime r = Runtime.getRuntime();
        Process p = null;
        String res = "";

        try {
                    p = r.exec(cmd);
                    InputStreamReader isr = new InputStreamReader(p.getInputStream());
                    BufferedReader br = new BufferedReader(isr);
                    String line = null;
                    //out.println(res);
                    while ((line = br.readLine()) != null) {

                    res += line;

                    }
                    p.waitFor();
                    } catch (Exception e) {
                    res += e;
                    }
                    System.out.println(p.exitValue());

        return res;

    }

© Stack Overflow or respective owner

Related posts about jsp

Related posts about java