Forums

Process called with Python3 acts very wierd when attaching to it from bash terminal

I have an Erlang application. I don't like bash so I wanted to use a script to start my program. All is nice but, to the erlang process, you can attach after you have started it, send commands and detach.

1) So in first case I start the program with python:

erl = "/home/ezio_auditore/IdeaProjects/chatserver/rel/mongooseim/bin/mongooseim"
opts = "start"

subprocess.check_call([erl, opts])

The I go an try to attach to the process with bash :

/home/ezio_auditore/IdeaProjects/chatserver/rel/mongooseim/bin/mongooseim attach
Attaching to /tmp//home/ezio_auditore/IdeaProjects/chatserver/rel/mongooseim/erlang.pipe.1 (^D to exit)

^L

I see some strange symbols, I don't have autocompletion anymore, and pressing up key for previous commands is not working ( instead it shows some ^[[A^[[A^[[A )

2) Now If I start the program from bash:

/home/ezio_auditore/IdeaProjects/chatserver/rel/mongooseim/bin/mongooseim start
/home/ezio_auditore/IdeaProjects/chatserver/rel/mongooseim/bin/mongooseim attach
Attaching to /tmp//home/ezio_auditore/IdeaProjects/chatserver/rel/mongooseim/erlang.pipe.1 (^D to exit)

(mongooseim@127.0.0.1)1>

All is fine. I am thinking that python is messing with some stuff, or I am missing some stuff. Please help, thanks

Hi there -- I'm a bit confused, I don't think we have erlang installed here. Where are you running this?

I have erlang installed at home r17. The behaviour is the same as opening the python console: I don't have autocompletion, the upper key doesn't work and also some output from the attached program doesn't seem ok. So I am using ubuntu 14.04 x64 erlang r17. Say if you need more info, thanks

We normally only support problems happening on PythonAnywhere here.

But one thing that occurs to me is that perhaps when you're starting the erlang process using subprocess.check_call, it's detecting that it's not running from a terminal (a PTY) but rather to another program, so it's behaving differently when you try to attach to it. There's a bit of information about what that means in the first 15 minutes or so of this talk I gave at EuroPython last year (amongst other things).

If that's the cause, you might have more luck using pty.fork instead of subprocess.check_call. But it's a lower-level interface so it will be more fiddly.

Do you have any knowledge of tutorials using fork to start a process? I mean I am sending a command to check_call but to fork is more abstract. Thanks

Try pexpect?