Executing * nix binaries in Python

I need to run the following command:

screen -dmS RealmD top

      

Basically, the GNU screen is called in the background with the session title 'RealmD', with the top command running inside the screen. The command MUST be called in such a way that the screen cannot be replaced at this time until the server is reinstalled. (Another project at another time)

I entered the top command for the binary server to be started. But top is a decent replacement while the code is being debugged for this python module.

I really need a way to execute the screen with the above parameters in Python.

+1


a source to share


2 answers


Use os.system :

os.system("screen -dmS RealmD top")

      



Then in a separate shell you can look top

by running screen -rd RealmD

.

+7


a source


os.system

is the easiest way, but for many other possibilities and degrees of freedom also see the standard library subprocess

module (unless Stephan202 simple usage os.system

meets all your needs, of course ;-) .

Edit Here's a standard replacement foros.system()



p = Popen("screen -dmS RealmD top", shell=True)
sts = p.wait()

      

http://docs.python.org/library/subprocess.html#replacing-os-system

+11


a source







All Articles