我做了个程序,上传到linux上,在这个程序中要执行一个shell命令(例如:
“chmod 755 /home/click/hello”命令)。我是直接在程序中加入这样的代码:(想看看能不能执行)  try {   Process proc =Runtime.getRuntime().exec("chmod 755 /home/click/hello");
   if(proc.exitValue()==0)
   {
    log.debug("QQQQQQQQQQQQQQQQQ");
   }   InputStreamReader ir = new InputStreamReader(proc.getInputStream());   LineNumberReader input = new LineNumberReader(ir);   String line;   while ((line = input.readLine()) != null) {
    log.debug("KKKKKKKKKKKKKKKKKKK:" + line);
   }
文件/home/click/hello是存在的。
运行程序的时候就是没有反应,我已经反复试过了,就是不好用。
谁有实现类似功能的全部代码?
先谢谢了!

解决方案 »

  1.   

    直接在shell下运行那个命令呢?
      

  2.   

    Process proc =Runtime.getRuntime().exec(" shell chmod 755 /home/click/hello");
    这样试试,我以前好像这样成功过的
    目前没环境不好测试:(
      

  3.   

    直接在shell下运行"chmod 755 /home/click/hello" 是成功的!
     
    我试过下面的方法
    String[] args = new String[] {"sh", "-c", "chmod 755 /home/click/hello"};
    Process proc =Runtime.getRuntime().exec(args);
    结果还是没反应!