DavidT
DavidT

Reputation: 461

How to send command via python to running screen (Ubuntu 12.04)

I am on Ubuntu 12.04 LTS running Python 2.7. My Python code looks somewhat like this:

from os import system
system("screen -S session -X stuff 'commandhere'`echo -ne '\015'`")

But when I try to run it, it does not do anything. I was wondering whether it was possible to fix this, and if so, how?

I am trying to send a command to an active screen "session" where "commandhere" is the command.

Upvotes: 1

Views: 3653

Answers (1)

Giacomo1968
Giacomo1968

Reputation: 26066

Have you tried subprocess.call() like this:

#!/usr/bin/python
import subprocess
subprocess.call(["screen", "-S", "session", "-X", "stuff", "'command here'`echo -ne '\015'`"])

Another idea: It might be best to just create a bash script to do the session manipulation stuff and just have Python then call the bash script.

Upvotes: 3

Related Questions