为什么 runtime.exec() 没有执行。当我给出 sshpass 命令时

Why runtime.exec() is not executing. when I given sshpass command

为什么 runtime.exec() 没有执行。当我给出 sshpass 命令时

rt.exec("sshpass -p sbsiz scp '/home/surendra/Desktop/remote_backup.txt' root@192.168.59.115:/home/");

但是当我 运行 直接在终端中执行此命令时,它的工作方式如下 在航站楼

sshpass -p sbsiz scp '/home/surendra/Desktop/remote_backup.txt' root@192.168.59.115:/home/

您可以检查进程 class 中的输入流和错误流(return for rt.exec)以查看导致命令未执行的实际错误是什么如下所示:

public static void printStream(InputStream is, String type){
try
   {
      InputStreamReader isr = new InputStreamReader(is);
      BufferedReader br = new BufferedReader(isr);
      String line=null;
      while ( (line = br.readLine()) != null)
            System.out.println(type + ">" + line);    
   } catch (IOException ioe){
           ioe.printStackTrace();  
   }
}

public static void main(String args[])
{
    String cmd = "command to execute";
    Process proc = Runtime.getRuntime().exec("sshpass -p sbsiz scp '/home/surendra/Desktop/remote_backup.txt' root@192.168.59.115:/home/");
    printStream(proc.getInputStream(), "OUTPUT");
    printStream(proc.getErrorStream(), "ERROR");
}