open_port and raw mode (zlogin)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

open_port and raw mode (zlogin)

Heinz Nikolaus Gies
Hi everyone,
I am trying to get Erlang to talk to (solarises) zlogin. I figured, open_port would be the logical step to do that BUT it dies horribly the command I run is:

open_port({spawn, "/usr/sbin/zlogin -C 8e3b630b-d18a-4047-bad3-600b17d9ef46"}, [use_stdio]).

also experimented with other port options but they don't' really make a difference safe for nouse_stdio which replaces the Erlang console with the zlogin one (which doesn't help much ;)

the error I get from zlogin is:

(chunter)8> open_port({spawn, "/usr/sbin/zlogin -C 8e3b630b-d18a-4047-bad3-600b17d9ef46"}, [use_stdio]).
zlogin: failed to get user terminal settings: Invalid argument
zlogin: failed to set stdin pty to raw mode: Invalid argument

I've tracked down that a bit further into the zlogin code and it seems to be related to a call to tcgetattr(fd, &term) in the code which fails with the open_socket created connection.

I'm a bit at a loss here what to do next sadly, any advice?

Regards,
Heinz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130125/6624c65e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 841 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130125/6624c65e/attachment.bin>

Reply | Threaded
Open this post in threaded view
|

open_port and raw mode (zlogin)

Patrik Nyblom
Hi!
On 01/25/2013 07:13 PM, Heinz Nikolaus Gies wrote:

> Hi everyone,
> I am trying to get Erlang to talk to (solarises) zlogin. I figured,
> open_port would be the logical step to do that BUT it dies horribly
> the command I run is:
>
> open_port({spawn, "/usr/sbin/zlogin -C
> 8e3b630b-d18a-4047-bad3-600b17d9ef46"}, [use_stdio]).
>
> also experimented with other port options but they don't' really make
> a difference safe for nouse_stdio which replaces the Erlang console
> with the zlogin one (which doesn't help much ;)
>
> the error I get from zlogin is:
>
> (chunter <mailto:chunter>)8>
> open_port({spawn, "/usr/sbin/zlogin -C
> 8e3b630b-d18a-4047-bad3-600b17d9ef46"}, [use_stdio]).
> zlogin: failed to get user terminal settings: Invalid argument
> zlogin: failed to set stdin pty to raw mode: Invalid argument
>
> I've tracked down that a bit further into the zlogin code and it seems
> to be related to a call to tcgetattr(fd, &term) in the code which
> fails with the open_socket created connection.
>
> I'm a bit at a loss here what to do next sadly, any advice?
>
It seems zlogin expects a terminal as stdin, but if you open_port, stdin
for the program will be a pipe, which you cannot do tcgetattr on. You
will need to either find an option to zlogin that expects input from
something not a terminal, or create a wrapper program that creates a pty
, starts zlogin and forwards data from/to the pty and the pipe (which
would be some hacking, but not impossible, that's basically what run_erl
does, but to/from a named pipe - possibly there's already a program out
there doing that, maybe someone on the list can enlighten us :))
> Regards,
> Heinz
>
Cheers,
/Patrik
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130125/228ffa5f/attachment.html>

Reply | Threaded
Open this post in threaded view
|

open_port and raw mode (zlogin)

Richard A. O'Keefe
In reply to this post by Heinz Nikolaus Gies
> Hi everyone,
> I am trying to get Erlang to talk to (solarises) zlogin.

Which wants its standard streams to be connected to a tty
or pty.  Sadly, while open_port/2 has a 'use_stdio' option,
it doesn't have a 'use_pty' option.  Is there any reason
that it couldn't?

I wonder if having Erlang run an expect(1) script that
then runs zlogin might do the trick?




Reply | Threaded
Open this post in threaded view
|

open_port and raw mode (zlogin)

Per Hedeland-4
In reply to this post by Patrik Nyblom
Patrik Nyblom <pan> wrote:
>
>On 01/25/2013 07:13 PM, Heinz Nikolaus Gies wrote:
[snip]

>>
>> I've tracked down that a bit further into the zlogin code and it seems
>> to be related to a call to tcgetattr(fd, &term) in the code which
>> fails with the open_socket created connection.
>>
>> I'm a bit at a loss here what to do next sadly, any advice?
>>
>It seems zlogin expects a terminal as stdin, but if you open_port, stdin
>for the program will be a pipe, which you cannot do tcgetattr on. You
>will need to either find an option to zlogin that expects input from
>something not a terminal, or create a wrapper program that creates a pty
>, starts zlogin and forwards data from/to the pty and the pipe (which
>would be some hacking, but not impossible, that's basically what run_erl
>does, but to/from a named pipe - possibly there's already a program out
>there doing that, maybe someone on the list can enlighten us :))

Yes, there is actually such a wrapper program included with the Lux tool
that H?kan Mattson announced here a while back (in
http://erlang.org/pipermail/erlang-questions/2012-May/066891.html).
It's called 'runpty' and can be found at
https://github.com/hawk/lux/tree/master/c_src - a little demo:

29> P = open_port({spawn, "/bin/sh"},[]).      
#Port<0.519>
30> P ! {self(), {command, "tty\n"}}.
{<0.57.0>,{command,"tty\n"}}
31> flush().
Shell got {#Port<0.519>,{data,"not a tty\n"}}
ok
32> erlang:port_close(P).
true
33> f(P).
ok
34> P = open_port({spawn, "runpty /bin/sh"},[]).
#Port<0.525>
35> P ! {self(), {command, "tty\n"}}.          
{<0.57.0>,{command,"tty\n"}}
36> flush().                                    
Shell got {#Port<0.525>,{data,"$ "}}
Shell got {#Port<0.525>,{data,"tty\r\n"}}
Shell got {#Port<0.525>,{data,"/dev/pts/12\r\n"}}
Shell got {#Port<0.525>,{data,"$ "}}
ok
37>

Note well that besides tty(1) working, the presence of a tty also (by
default) results in echo, pesky CRLF line termination, and an
interactive shell. It should work fine to just pass "runpty zlogin ..."
to open_port/2 though, but I haven't tried that.

--Per Hedeland


Reply | Threaded
Open this post in threaded view
|

open_port and raw mode (zlogin)

Heinz Nikolaus Gies
On Jan 27, 2013, at 14:07, Per Hedeland <per> wrote:
...
> Yes, there is actually such a wrapper program included with the Lux tool
> that H?kan Mattson announced here a while back (in
> http://erlang.org/pipermail/erlang-questions/2012-May/066891.html).
> It's called 'runpty' and can be found at
> https://github.com/hawk/lux/tree/master/c_src - a little demo:
>
...

Per,
you (and H?ken of cause ;) are a lifesavers! this works like a charm :) thank you so much!

Regards,
Heinz