pseudo terminals

Cameron Simpson cs at zip.com.au
Fri Sep 18 03:32:49 UTC 2009


On 17Sep2009 18:19, devi <devi at atc.tcs.com> wrote:
| On Thu, 2009-09-17 at 08:09 +1000, Cameron Simpson wrote:
| > On 16Sep2009 19:43, devi <devi at atc.tcs.com> wrote:
| > | On Wed, 2009-09-16 at 11:18 +0100, Dave Mitchell wrote:
| > | > On Wed, Sep 16, 2009 at 03:06:09PM -0400, devi wrote:
| > | > > 	The command 
| > | > > echo "service httpd status " > /dev/pts/1 is executed on one terminal,
| > | > > let us assume it as t1.  
| > | > > The echo command is executed on t1 but the output(service httpd status"
| > | > > is directed to /dev/pts/1 terminal.
| > | > > 
| > | > > What I am saying is that the output  is redirected directly to the
| > | > > terminal /dev/pts1/1.
| > | > > The output here is "service httpd status", which is generally a command.
| > | > > And so it gets executed.
| > | > 
| > | > No, the text just appears in the terminal associated with /dev/pts1/1;
| > | > it does not not cause the command to be executed. That is to say,
| > | > you can't use this as a mechanism to insert characters into a another
| > | > terminal's input buffer.
| > | > 
| > | But the command got executed, and it gave the status of apache
| > | on /dev/pts/1 terminal.
| > 
| > That's quite interesting. It should _not_ cause the command to be
| > executed, and I really believe something more is going on.
| > 
| > /dev/pts/1 is the "slave" side of the pseudoterminal; all pseudoterminals
| > have a "master" side and a "slave" side.
| 
| Here, the /dev/pts/1 is the tty of a virtual machine.  This virtual
| machine is created by xen.
| Yes, I have come across master and slave pseudo terminals, but I have
| not set any anything like that.

Ah, ok. I have not used such a setup. However, it looks like Xen
arranges the master slave setup. What it presents is like a crossover
terminal connection. /dev/pts/1 is cross wired to the temrinal inside the Xen
VM; functionally it will behave like the "master" side of a pseudo tty.
Internally it will really be a pseudoterminal, with Xen as the master,
and Xen passes stuff through to the VM for you.

As, indeed, you have shown it does.

| I have done, what you suggested, it's the same.  Anyways my requirement
| is that, after the command is executed on /dev/pts/1, I should be able
| to get the return value on the terminal "t1"
| 
| eg:
| 	rc=`echo "service httpd status" > /dev/pts/1"
| I thought rc will hold the return value, but it displays nothing.

Ok.

I believe, based on your description, that reading from /dev/pts/1
will collect the output you want.

Try this:

  tee -a output.log </dev/pts/1 >/dev/null &
  teepid=$!
  echo "service httpd status" >/dev/pts/1
  sleep 5
  kill $teepid

and then look at the file output.log.

Your `echo .... >/dev/pts/1` incantation did not contain the output
because it collects the output of "echo" (specificly, any output not
send elsewhere; your >/dev/pts/1 sends it elsewhere and so the output
is empty).

Nothing was reading from the pty.

What my suggestion above does is start a "tee" command in the background
to read from the pty and copy the data to the file output.log. Then
we run your echo, to run the command on the VM. Then we wait a few
seconds. Then we kill the "tee" command.

Commentry:

- a simpler command than the "tee" would be:
    cat /dev/pts/1 >output.log &
  however, "cat" (like almost all other programs) will be buffering its
  output for efficiency purposes, so it will never write to output.log
  before we kill it. "tee" does not buffer.

- the output recorded in output.log (if the above stuff works for you)
  will be the data stream sent to the terminal. That is, it will
  probably end lines with both CR and NL characters. Many rc files
  will emit coloured text in their output if on a terminal; your
  output.log file will contain the terminal escape sequences used to
  drive those colours. And so forth.

- you have no real indication of when the "service httpd status" command
  finishes, hence the dodgy "sleep 5" above.

You would be far better connecting to the VM with a remote command tool
like ssh.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

A novice of the temple once approached the Chief Priest with a question.

  "Master, does Emacs have the Buddha nature?" the novice asked.

  The Chief Priest had been in the temple for many years and could be relied
  upon to know these things.  He thought for several minutes before replying.

  "I don't see why not.  It's got bloody well everything else."

  With that, the Chief Priest went to lunch.  The novice suddenly achieved
enlightenment, several years later.

Commentary:

        His Master is kind,
        Answering his FAQ quickly,
        With thought and sarcasm.




More information about the users mailing list