Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top