Hi all!

I am using the Expect module to establish and manage an ssh connection to execute some commands and read the answer from a server.

Up to the moment, my script executes a fixed list of commands. I've been using a hard-coded list of commands or a file containing the list.

But now I need to add commands to the list during run time. Furthermore, the program should know immediately if a new command has arrived and execute it (if there weren't other commands waiting). And it should not stop listening to the ssh connection while waiting for these new commands. Commands that come from another Perl process in the same computer.

So I need IPC to allow the Expect-running process to get and immediately detect new commands; while at the same time this Expect-running process is expecting on the ssh shell.

My first question is: Which kind of IPC should I use to transmit the new commands? Maybe a pipe? a socket?

I guess there are more than one valid way to do that... but recommendations are welcome!

The second question is: How can I achieve the coordination?

I read that Expect may listen to multiple process at the same time. So maybe there is a way to establish a pipe or similar from the process that sends new commands to the Expect-running process, and make the last use Expect on that pipe to get the new commands (at the same time it is expecting on the ssh shell). But I'm not sure whether Expect may work also with pipes (or filehandles in general) or if it works only with commands.

In case that can't be done, which is the best way (compatible with Expect) to communicate between processes that a new command is ready on the list.

Thanks in advance and sorry for the long text!


In reply to Inter-process communication when using Expect.pm by nmorenod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.