嗨,我尝试从java/war文件执行python。Tomcat可以访问这个文件,因为它生成了这个文件。作为pi或root用户,我可以毫无问题地执行生成的脚本文件。但是tomcat8进程没有正确运行脚本文件。你知道吗
出于某种原因,我无法通过su tomcat8来更改tomcat8用户,以尝试tomcat8用户是否可以,我不理解。你知道吗
我用这个密码
public static void executePythonScript(String pathScriptFile) {
try{
File f = new File(pathScriptFile);
System.out.println(f.getAbsolutePath() +" exists:"+ f.exists());
ProcessBuilder pb = new ProcessBuilder("python", pathScriptFile);
Process p = pb.start();
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String ret = in.readLine();
System.out.println("value is : "+ret);
}catch(Exception e){System.out.println(e);}
}
@RequestMapping(value="/api/togglegaragedoor")
public String toggleGarageDoor() {
try {
String prg = "#!/usr/bin/env python\n\nimport automationhat\\n\nautomationhat.relay.one.on()";
BufferedWriter out = new BufferedWriter(new FileWriter("/home/pi/Pimoroni/automationhat/examples/relay_on.py"));
out.write(prg);
out.close();
String prg2 = "#!/usr/bin/env python\n\nimport automationhat\\n\nautomationhat.relay.one.off()";;
BufferedWriter out2 = new BufferedWriter(new FileWriter("/home/pi/Pimoroni/automationhat/examples/relay_off.py"));
out2.write(prg2);
out2.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Api.executeCommand("which python");
Api.executePythonScript("/home/pi/Pimoroni/automationhat/examples/relay_on.py");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Api.executePythonScript("/home/pi/Pimoroni/automationhat/examples/relay_off.py");
return "toggled";
}
我没有得到任何错误。pi应该触发一个没有点击的继电器。返回的值为空。中继正在以pi用户身份单击。python exe是相同的(哪个python.)
“/home/pi/Pimoroni/automationhat/examples/automationhat/init.py”,LINE 354,安装中 _ads1015=ads1015(smbus.smbus文件(1)) IOError:[Errno 13]权限被拒绝
GPIO.setup(self.pin, GPIO.OUT, initial=0)
运行时错误:无法访问/dev/mem。尝试以root身份运行!你知道吗
谢谢你。。。这是它需要添加tomcat8用户到sudoers文件没有密码和执行python脚本与sudo。。。你知道吗
相关问题 更多 >
编程相关推荐