I Asked some days ago about executing python script from java. It solved my problem partially. But now, I am not able to pass any parameter and make that script to do anything.
My script has to receive a XBee frame and send it by serial port. I tested the script in shell and it works fine. So, doing: sudo python script.py frame
, the frame is sent.
Now, I tried to do the same with java, and it fails. My code is:
Process p;
//System.out.println(packet.toString());
try{
StringBuffer p1 = new StringBuffer();
String[] cmd = {"/bin/bash", "-c", "echo pass | python script.py b'", packet.toString(), "'"};
p = Runtime.getRuntime().exec(cmd);
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s = br.readLine();
p.waitFor();
p.destroy();
} catch (Exception e) {}
I have to add b' before argument and another ' after it. packet is StringBuffer so I get the String with toString method.
I need to run it as root because it uses serial port and if not, it says to me I have not permission.
Do you know how to do it? I tried to write a file with some word when I run the script but nothing happends, which makes me think about it doesn't run properly.