@param execStr String 命令字符串
String[] args = new String[] {"sh", "-c", execStr};//执行linux下的命令
Runtime.getRuntime().exec(args);

解决方案 »

  1.   

    Runtime.getRuntime().exec("/usr/sbin/ls /root >/root/a.txt"); 
    这样才对哦!
      

  2.   

    首先感谢 yorsun80(啊呜)  和 robber(海盗) 朋友的热心指点。
        如果我想执行一个java程序,该怎么做呢?
        Runtime.getRuntime().exec("java -classpath . myhelloworld"); 不好使啊。
        Runtime.getRuntime().exec("/usr/local/j2sdk1.4.1_03/bin/java -classpath . /root/helloworld"); 也不好使啊。
      

  3.   

    ft!java里再开java进程,为什么不是直接new myhelloworld呢?
      

  4.   

    如windows下,我还知道,呵呵,
      

  5.   

    Runtime.getRuntime().exec("cmd /c java -cp . myhelloworld");
      

  6.   

    Process process = Runtime.getRuntime().exec("cmd /c explorer");windows2000下完全可以啊!
      

  7.   

    windows2000下是完全可以啊,但是现在的问题是:在Linux上怎么实现啊?
      

  8.   

    Process p = Runtime.getRuntime().exec("/usr/sbin/ls /root >/root/a.txt"); 
    in = p.getInputStream();
    in.read();可以读到执行结果。奇怪!你怎么还没有搞定?
    ============================
      

  9.   

    刚巧找了一个---看下对你有没有点帮助
         try          {              process = Runtime.getRuntime().exec (command);              InputStreamReader ir=newInputStreamReader(process.getInputStream());              LineNumberReader input = new LineNumberReader (ir);              String line;              while ((line = input.readLine ()) != null)                  System.out.println(line);          }          catch (java.io.IOException e){             System.err.println ("IOException " + e.getMessage());          }