0

I need to: 1. Capture the output of a process in a log file, but 2. Do it detached, since the program can take hours, (or days).

Apparently, if you use QProcess.startDetached(command), you lose your StandardOutput, so that

launchApp = QtCore.QProcess()        
launchApp.setStandardOutputFile("logfile")
launchSim.startDetached("my_command")

does not work.

launchSim.start("my_command")

DOES work, but I can't afford the tie-up. Also

launchSim.startDetached("my_command", " > logfile") 

does not work. It sees "> logfile" as an illegal option to "my_command"

This is on Linux


The problem is that "my_command" dies when the calling program closes. nohup doesn't seem to help. (Not sure why).

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Paul Nelson
  • 1,291
  • 4
  • 13
  • 20

1 Answers1

1

How about using os.system() from the standard lib:

import os
os.system("nohup my_command > logfile &")

probably a bit better and safer would be:

import os
os.system("nohup /full/path/to/my_command >& logfile &")

Notice the redirection of both output streams and the full path to command. Also you might be interested to look at os.popen() and the subprocess module.

snies
  • 3,461
  • 1
  • 22
  • 19