2

I am running a Java program, and with the Java program, I run a Python script. The python script (with subprocess.Popen) runs the command

screen -x hg1 -X stuff "jsp sign edit status1 2 test line $(printf '\r')"

...but when it does that, it retuns the error

Must be connected to a terminal.

I tried doing many things, including doing a bunch of switches (e.g. -dm, -d, -m, etc.), but none of them work.

How do I make screen stuff a command without giving me that error?

5
  • Maybe you can try tmux? I'm not sure if it will work differently, but you can try it.
    – Keith
    Jan 2, 2014 at 0:33
  • What you're actually trying to accomplish? To me it sounds like using screen/tmux is just added complexity as you don't state any reason why your commands should be run through screen.
    – user260419
    Jan 2, 2014 at 3:59
  • @SamiLaine I'm trying to send a command to a Minecraft server that is running in a screen session.
    – Ivan
    Jan 2, 2014 at 19:37
  • My suspicion is that your Python call is flawed somehow. Does subprocess.call(['screen', '-x', 'hg1', '-X', 'stuff', 'jsp sign edit status1 2 test line \r']) not work? Calling shell from Python called from Java sounds like you have a lot you want to simplify anyway.
    – tripleee
    Apr 17, 2018 at 12:35
  • Have you tried to force the allocation of a terminal by putting something like ssh -t localhost before the screen command? Feb 4, 2020 at 0:08

2 Answers 2

2

I think your problem is that you don't have an interactive shell terminal session from inside the python script; there's no tty allocated. You might want to try the python pty module.

If you already had an interactive terminal, you could try script /dev/null, then screen.

1

Try this:

screen -dm -x hg1 -X stuff "jsp sign edit status1 2 test line $(printf '\r')"

You can find more infos here: http://www.computerhope.com/unix/screen.htm

You must log in to answer this question.

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