1

So in Python, I am trying to create a unix screen and have it execute a command but it does not work. The screen isn't event created and I can't see it if I run screen -ls

This is the code:

def run_screen_with_command(command):
    screens = []

    command = ['screen', '-d', '-m', '-S', 'myscreen', 'bash', '-c', "'{}'".format(command)] 
    process = subprocess.Popen(command,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT)

    process.wait()
    print(process.stderr, process.stdout.read())
    #returncode = process.wait()
    print ' '.join(command)

    return process


run_screen_with_command('sleep 10')

1 Answer 1

2

You don't need to quote the argument for bash -c, since the shell isn't executing it.

command = ['screen', '-d', '-m', '-S', 'myscreen', 'bash', '-c', command]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.