gpt4 book ai didi

linux - bash 脚本在 jee 上调用时不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 05:22:50 25 4
gpt4 key购买 nike

我有一个需要参数的 bash 脚本。

当我直接从 putty 调用它时,它可以工作,当我从我的 jee 程序中调用它时,它不起作用并且不会向我显示任何错误。

这是我的java代码:

String[] cmdArray = {"sudo", "ssh", "-tt", "root@89.40.112.248", "/root/dve", "-l", "89.40.112.120,89.40.112.248", "you.mp4", "-s",".teeeest.avi" };

List<ObjectNode> listFileNode = new ArrayList<ObjectNode>();

try{
Runtime rt = Runtime.getRuntime();
ProcessBuilder pb = new ProcessBuilder(cmdArray);
Process proc = pb.start(); // Start the process.
System.out.println("Script executing");
rc= proc.waitFor(); // Wait for the process to finish.
System.out.printf("Script executed successfully in ", rc);

InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);

String line = null;
System.out.println("<ERROR___EXEC>");
while ( (line = br.readLine()) != null){

System.out.println(line);
node.put("line",line );
listFileNode.add(node);
}
System.out.println("</ERROR___EXEC>");
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);


InputStream processInputStream =proc.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(processInputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

System.out.println("<RESULTAT___EXEC>");
while ( (line = bufferedReader.readLine()) != null){

System.out.println(line);
node.put("lineR",line );
listFileNode.add(node);

}
System.out.println("</RESULTAT___EXEC>");

}catch (Throwable t)
{
t.printStackTrace();
}

请帮助我,我被困在这个问题上一周了,但没有找到解决方案

最佳答案

您不能在java代码中使用sudo命令。如果您需要运行 root 特权应用程序,则需要在运行 java 代码之前切换到 root。

如果你想从你的java代码中做到这一点,你需要调用 setuid 。但我不知道你可以从 java 代码调用 setuid 。为此,您可能需要一个 C/C++ 包装器来切换到根目录。引用:http://unix.stackexchange.com编写包装器的问题。

关于linux - bash 脚本在 jee 上调用时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38586666/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com