1

I have a python script that I run by passing some arguments as environment variables:

param=1 length=5 python myscript.py

I want to run it inside a screen. I tried screen -m param=1 length=5 python myscript.py but this does not work, I get the error "Cannot exec param=1, no such file or directory". How can I still run this script within a screen?

1
  • 2
    Can't you use something like screen -m bash -c 'param=1 length=5 python myscript.py'?
    – pfnuesel
    Commented Aug 7, 2017 at 23:24

1 Answer 1

1

Try:

param=1 length=5 screen -m python myscript.py

Example

$ cat myscript.py
#!/usr/bin/python
import os
print(os.environ["param"], os.environ["length"])
raw_input()

If we run this command:

$ param=1 length=5 screen -m python myscript.py

The output appears:

('1', '5')

(For python3, replace raw_input with input. Also, note that the output will display slightly differently.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .