Hi all,
I'm having tough time on how to use linux commands from the servlets. I am able to run the commands from java program but I can't run the same program from servlets? Is there a way to do this?
Here is a sample of my code that runs the command $gedit /home/syum/test.txt from a java code and its working fine. But when used a servlet to run the same code, nothing happens.

import com.sun.corba.se.spi.orbutil.fsm.Input;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;

public class runSystemCommand {

    public static void main(String args[]) {
        Runtime r = Runtime.getRuntime();
        Process p = null;
        String test = "/home/syum/test";
        String cmd = "gedit " + test;
        try {
            p = r.exec(cmd);
            InputStreamReader isr = new InputStreamReader(p.getInputStream());
            BufferedReader br = new BufferedReader(isr);
            String line = null;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
            p.waitFor();
        } catch (Exception e) {
            System.out.println(e);
     }
         
}

How do I call this same program so that I can run from a servlet?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.