0

I am calling the following command via bash but it is not creating screen session at all:

screen -d -m time python3 myscript.py ; sleep 1

when I do screen -r it says no screen to resumed. However when I try:

screen -d -m time python3; sleep 1

Then on doing screen -r it does show Py console.

What wrong am I doing?

3
  • 1
    perhaps the "python3 myscript.py" command is failing?
    – Jeff Schaller
    Commented May 24, 2017 at 16:56
  • if it fails it should have given error. I got none. And BtW the command works fine if I do screen first and then run
    – Volatil3
    Commented May 24, 2017 at 18:18
  • 1
    When the python script finishes, that screen is destroyed. Since there are no more screens in the session, the session goes away. The second one works because it starts an interactive Python interpreter, not a script.
    – Barmar
    Commented May 24, 2017 at 19:09

1 Answer 1

1

screen -d -m time python3 myscript.py runs python3 myscript.py inside a screen session, then exits. If you don't see that screen session later, it's because the script has already exited.

It seems that you expected myscript.py to run for longer. Something must have gone wrong. Redirect the output (especially errors) to a file to see what's going on. Or keep the session around by running another program.

screen -d -m time sh -c 'python3 myscript.py; echo $?; sleep 999999999'

If the script doesn't work when you run it directly from screen, but works if you run it from an interactive shell, it's very likely that this indicates two things:

  • myscript.py relies on some setting, probably an environment variable. It isn't self-contained.
  • You're setting this setting in the wrong place. You're probably setting an environment variable in .bashrc, which is only read by interactive shells. Set environment variables in .profile instead; this file is read when you log in.
2
  • It does run longer ( for hours) hence chance of it's over is none, it also creates a text file. As far as setting, no it i snot relying on any such file.. however it does read info from text file and their absolute path already set
    – Volatil3
    Commented May 25, 2017 at 4:57
  • There were two issues, sleep time was less, I increased upto 5 seconds so that the script could get initiated, second, the path of input reading file was wrong.
    – Volatil3
    Commented May 25, 2017 at 5:24

You must log in to answer this question.

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