[Django]-Running command in background

2👍

The problem is likely due to the bash shell terminating immediately after the & and sending the SIGHUP singal to all of it’s subprocesses (standard shell behavior).

You can use the subprocess module to directly execute the command and can redirect the output to tmp.txt yourself by first opening the file and then by passing it’s file handle to the stdout argument of the Popen call.

👤Rakis

2👍

There is a problem with os.getlogin() and subprocessing and python.
See http://code.activestate.com/lists/python-list/288845/

You need to use something else, such as:

pwd.getpwuid(os.getuid()).pw_name (Unix only)

See also the discussion on a portable way to get the username.

👤brita_

0👍

Try changing it to ['vxswadm', 'listswitch', 'all', '>', 'tmp.txt','&'] and/or changing shell to False.

I think it might be the shell bit, though (if that fixes it).

You may also try adding stdin=subprocess.PIPE, stdout=subprocess.PIPE, though I doubt that will affect it.

Leave a comment