 |
|
 |
|
|
 |
GNU readline / tty related questions |
 |
 |
|
|
05-25-07 06:19 PM
Hi,
I have to control a tool "A", that uses the GNU readline library for
it's command line, 'remotely' from another process "B". Currently I
send commands to and receive the output from the tool "A" via pipes.
The problem is that for example sending a <Tab> from "B" to "A"
doesn't start Tab-Completion and <Cursor-Up> doesn't read from the
history.
How can I have every key, that is typed in "B", sent to "A" so that it
is immediately interpreted as if it was typed in "A"s command line?
A problem that is probably related to this question is that, when
starting "A" via "execl(".../tool",...)" inside "B", the tool "A"
recognizes by calling isatty(), that it is not connected to a
terminal. Can I attach it to a tty before or after "execl()"? If not,
another option is to start "A" first on a terminal, if I can later
grab/send to that terminal from the control process "B" as mentioned
above.
Any clues how to do this?
Thanks
Edi
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: GNU readline / tty related questions |
 |
 |
|
|
05-26-07 06:21 AM
In article <1180103675.094305.230600@p47g2000hsd.googlegroups.com>,
emiller_news@yahoo.com wrote:
> Hi,
> I have to control a tool "A", that uses the GNU readline library for
> it's command line, 'remotely' from another process "B". Currently I
> send commands to and receive the output from the tool "A" via pipes.
>
> The problem is that for example sending a <Tab> from "B" to "A"
> doesn't start Tab-Completion and <Cursor-Up> doesn't read from the
> history.
The readline library probably only processes control characters
specially when its input is a tty, not a pipe.
>
> How can I have every key, that is typed in "B", sent to "A" so that it
> is immediately interpreted as if it was typed in "A"s command line?
>
> A problem that is probably related to this question is that, when
> starting "A" via "execl(".../tool",...)" inside "B", the tool "A"
> recognizes by calling isatty(), that it is not connected to a
> terminal. Can I attach it to a tty before or after "execl()"? If not,
> another option is to start "A" first on a terminal, if I can later
> grab/send to that terminal from the control process "B" as mentioned
> above.
>
> Any clues how to do this?
Use a pseudo-tty (pty) rather than a pipe. You might want to make use
of Expect, a scripting language specifically designed for controlling
interactive programs.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: GNU readline / tty related questions |
 |
 |
|
|
05-26-07 12:21 PM
On May 25, 10:34 pm, emiller_n...@yahoo.com wrote:
> Hi,
> I have to control a tool "A", that uses the GNU readline library for
> it's command line, 'remotely' from another process "B". Currently I
> send commands to and receive the output from the tool "A" via pipes.
>
> The problem is that for example sending a <Tab> from "B" to "A"
> doesn't start Tab-Completion and <Cursor-Up> doesn't read from the
> history.
>
> How can I have every key, that is typed in "B", sent to "A" so that it
> is immediately interpreted as if it was typed in "A"s command line?
>
> A problem that is probably related to this question is that, when
> starting "A" via "execl(".../tool",...)" inside "B", the tool "A"
> recognizes by calling isatty(), that it is not connected to a
> terminal. Can I attach it to a tty before or after "execl()"? If not,
> another option is to start "A" first on a terminal, if I can later
> grab/send to that terminal from the control process "B" as mentioned
> above.
>
> Any clues how to do this?
>
readline may judge the input is a normal file desciptor or a tty...
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: GNU readline / tty related questions |
 |
 |
|
|
05-28-07 06:19 PM
On 26 Mai, 03:25, Barry Margolin <bar...@alum.mit.edu> wrote:
> Use a pseudo-tty(pty) rather than a pipe. You might want to make use
> of Expect, a scripting language specifically designed for controlling
> interactive programs.
Can you point me to some HOWTO or examples?
Thanks
Edi
>
> --
> Barry Margolin, bar...@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
> *** PLEASE don't copy me on replies, I'll read them in the group ***
[ Post a follow-up to this message ]
|
|
|
 |
|
|
|
 |
Re: GNU readline / tty related questions |
 |
 |
|
|
05-28-07 06:19 PM
emiller_news@yahoo.com wrote:
> On 26 Mai, 03:25, Barry Margolin <bar...@alum.mit.edu> wrote:
>
[vbcol=seagreen]
> Can you point me to some HOWTO or examples?
You apparently haven't tried typing "expect" into google and
clicking on the first link.
- Logan
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: GNU readline / tty related questions |
 |
 |
|
|
05-29-07 12:23 PM
On May 28, 7:55 pm, Logan Shaw <lshaw-use...@austin.rr.com> wrote:
> emiller_n...@yahoo.com wrote:
>
>
> You apparently haven't tried typing "expect" into google and
> clicking on the first link.
>
> - Logan
I think expect is the traditional way to do this. Pipe will help till
you the receiver application reads from stdin but other applications
like telnet, passwd can't be used with pipes. Expect runs over tcl,tk
has regular expression features and controls the flow based on what
the program 'expect's from the output.
Expect is used a lot in automation of command line based utilities
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: GNU readline / tty related questions |
 |
 |
|
|
05-29-07 06:22 PM
On 28 Mai, 16:55, Logan Shaw <lshaw-use...@austin.rr.com> wrote:
> emiller_n...@yahoo.com wrote:
>
>
> You apparently haven't tried typing "expect" into google and
> clicking on the first link.
Correct. I was visiting some other pages on Expect. My impression is
that Expect is not exactly targeted at my purposes although it might
be possible to use it with some detouring. So I put my question more
specifically:
How can I open a tty or pty from a C/C++ program, start a process
inside that terminal and have character-level communication between
the C/C++ program and the terminal input/output?
If this is possible with Excpect, this is fine, but it wouldn't help
me in the long run, because I can't use an intermediate Tcl program,
nor does the Tcl code help me with the C implementation.
Thanks
Edi
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: GNU readline / tty related questions |
 |
 |
|
|
05-30-07 06:21 AM
emiller_news@yahoo.com wrote:
> How can I open a tty or pty from a C/C++ program, start a process
> inside that terminal and have character-level communication between
> the C/C++ program and the terminal input/output?
>
> If this is possible with Excpect, this is fine, but it wouldn't help
> me in the long run, because I can't use an intermediate Tcl program,
> nor does the Tcl code help me with the C implementation.
Tcl/Expect is Open Source and contains a C implementation of exactly
what you're talking about. It uses a pty and spawns a program in it.
Also, I believe the Tcl interpreter is specifically designed to be easy
to embed in another program (so that it is not a separate executable),
so maybe that is an option.
- Logan
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: GNU readline / tty related questions |
 |
 |
|
|
05-30-07 12:17 PM
On 30 Mai, 08:15, Logan Shaw <lshaw-use...@austin.rr.com> wrote:
> emiller_n...@yahoo.com wrote:
>
>
> Tcl/Expect is Open Source and contains a C implementation of exactly
> what you're talking about. It uses a pty and spawns a program in it.
>
> Also, I believe the Tcl interpreter is specifically designed to be easy
> to embed in another program (so that it is not a separate executable),
> so maybe that is an option.
>
> - Logan
Logan, I am asking in c.u.p, because I hope to receive a few concise
hints about programming techniques, not about programs that are doing
what I try to do. Of course this problem has been solved in several
open source projects and I can learn about the techniques by studying
some 10000 lines of code, and you can call me lazy because I hope that
somebody more experienced than I might save me the time to do this.
So, if you can tell me how to open a pty in the way I asked, or if you
can point me to the relevant code in Expect, I'd consider your reply
really useful.
Thanks
Edi
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: GNU readline / tty related questions |
 |
 |
|
|
05-30-07 12:17 PM
In article <1180443510.886885.264030@k79g2000hse.googlegroups.com>,
emiller_news@yahoo.com wrote:
> How can I open a tty or pty from a C/C++ program, start a process
> inside that terminal and have character-level communication between
> the C/C++ program and the terminal input/output?
See openpty(3)
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
[ Post a follow-up to this message ]
|
|
|
 |
|
|
|
|
Sponsored Links |
 |
 |
|
|
 |
All times are GMT. The time now is 12:39 AM. |
 |
|
|
 |
|
 |
|
|
 |
|
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
|
|
|
|
Medical and Health forum | Computer Games Reviews | Graphics design forum
|
 |
|
 |
|