0

I need to track and launch few BASH scripts as process (if they for some reason crashed or etc). So i was trying as below: but not working

  def ps(self, command):
    process = subprocess.Popen(['/bin/bash'], shell=False, stdin=subprocess.PIPE,  stdout=subprocess.PIPE)
    process.stdin.write(command + '\n')
    process.stdout.readline()

  ps("/var/tmp/KernelbootRun.sh")
  ps("ps aux | grep processCreator.py | awk '{print $2}' | xargs kill -9")

None is working.

1

2 Answers 2

1

How about running it through a subshell with disown:

import os
def ps(self, command):
  os.system(command + " & disown")

ps("/var/tmp/KernelbootRun.sh")
ps("ps aux | grep processCreator.py | awk '{print $2}' | xargs kill -9")

Note that sometimes you have to use a null input and output to keep your process active when the terminal is closed:

ps("</dev/null /var/tmp/KernelbootRun.sh >/dev/null 2>&1")
ps("</dev/null ps aux | grep processCreator.py | awk '{print $2}' | xargs kill -9 >/dev/null 2>&1")

Or perhaps define another function:

def psn(self, command):
  os.system("</dev/null " + command + " >/dev/null 2>&1 & disown")

psn("/var/tmp/KernelbootRun.sh")
psn("ps aux | grep processCreator.py | awk '{print $2}' | xargs kill -9")
Sign up to request clarification or add additional context in comments.

Comments

0

This works great, as stand-alone process for my movie.

p.py:

import subprocess
subprocess.Popen("/var/tmp/runme.sh", shell=False, stdin=subprocess.PIPE,  stdout=subprocess.PIPE)

runme.sh:

#!/bin/bash
export DISPLAY=:0.0 
vlc /var/tmp/Terminator3.Movie.mp4

1 Comment

I think vlc does run independent of the terminal by default so I'm not sure if that would apply with other commands.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.