Task is to execute bash script from python script and let it execute on background, even if python script will finish. I need UNIX solution and i do not care if it will be not working on Win.
Python script :
#!/usr/bin/env python
import os, commands
command = '/usr/bin/ssh localhost "/home/gd/test/python/back.sh " '
print os.spawnlp(os.P_NOWAIT,command)
print "Python done"
/home/gd/test/python/back.sh :
#!/usr/bin/bash
/bin/echo "started"
/bin/sleep 80
/bin/echo "ended"
The issue is, when python script starts , i see PID of spawned process printed. But there is no process on background. When i use P_WAIT i see exit code 127 which means that command not found in the path. But i already provided all paths that already possible?
These scripts works perfectly with commands.getouput.
Something like this should work
Note that it’s preferable to use the subprocess module here instead of spawn