tags:

views:

113

answers:

2

I need to run the following command:

screen -dmS RealmD top

Essentially invoking GNU screen in the background with the session title 'RealmD' with the top command being run inside screen. The command MUST be invoked this way so there can't be a substitute for screen at this time until the server is re-tooled. (Another project for another time)

I've subbed in the top command for the server binary that needs to run. But top is a decent substitute while the code is being debugged for this python module.

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

+5  A: 

Use os.system:

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

Then in a separate shell you can have a look at top by running screen -rd RealmD.

Stephan202
Thank you very much!
Caedis
Why not use subprocess?
S.Lott
Because I didn't know about it until now :)
Stephan202
It's always a good idea to browse the Python standard library.
ΤΖΩΤΖΙΟΥ
+10  A: 

os.system is the simplest way, but, for many more possibilities and degrees of freedom, also look at the standard library subprocess module (unless Stephan202's wonderfully simple use of os.system meets all your needs, of course;-).

Edit Here's the standard replacement for os.system()

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

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

Alex Martelli