I have a shell command that executes a command and sends it through pipe to a python file. The python file does various checks on it and then starts processes with parameters using subprocess.Popen. But I see that it only works when I run the entire thing in a shell. Is there another way for me to execute it other than shell. If I just run it without any shell or use & to keep it at background, the processes started by python are named defunct in the ps -e table. Can someone help?
EDIT:
Here is run.sh, which I run :
#!/bin/bash
padsp julius -input mic -C $HOME/project/julius-grammer/julian.jconf | python -u $HOME/project/pythonControls/getcommand.py
However not all subprocess.popen fail to run. For example, if I use festival program, it runs. However xbacklight doesn't.
this is getcommand.py:
I removed the unnecessary part, and this the one that is necessary, com is string, I know this selection is going on fine.:
if(com == "COMPLETE BRIGHTNESS"):
userin = Data(["xbacklight", "-set", "100"],"Maximum brightness")
userin.interact()
if(com == "HALF BRIGHTNESS"):
userin = Data(["/usr/bin/xbacklight", "-set", "50"],"Partial brightness")
userin.interact()
if(com == "ZERO BRIGHTNESS"):
userin = Data(["/usr/bin/xbacklight","-set", "0"],"Minimal brightness")
userin.interact()
Now coming to the objects, this is how the class goes:
class Data:
def __init__(self, com="", msg="", sp="False"):
self.command = com
self.message = msg
self.speak = sp
def interact(self):
if self.command != "":
co = subprocess.Popen(self.command,stdout=subprocess.PIPE)
co.wait()
if self.speak == True:
self.say(self.message)
else:
subprocess.Popen(["notify-send","SysSec", self.message])