Java 从特定目录运行jsch和sudo

Java 从特定目录运行jsch和sudo,java,linux,Java,Linux,我已经连接到远程ubuntu服务器。在连接时,我想执行下面的shell命令 String command = "cd "to some directory" ; sudo ./i3lsdd"; // want to move to a directory and execute sudo ./i3lsdd command. 我使用了以下代码,但它给出了此错误: sudo:没有tty存在,也没有指定askpass程序抱歉,请重试 又来了。” 非常感谢您的帮助 将命令“sudo./i3lsdd

我已经连接到远程ubuntu服务器。在连接时,我想执行下面的shell命令

String command = "cd "to some directory" ; 
sudo ./i3lsdd"; 
// want to move to a directory and execute sudo ./i3lsdd command.
我使用了以下代码,但它给出了此错误:

sudo:没有tty存在,也没有指定askpass程序抱歉,请重试 又来了。”

非常感谢您的帮助

将命令“sudo./i3lsdd”保存在主目录的.sh文件中

使用获取主目录路径

String path = channelSftp.pwd();
如下所示编写命令

String command = "sudo -S " + path + "/scriptname.sh"; 
请使用以下代码提供密码

out1.write((sudo_pass + "\n").getBytes()); 
out1.flush();