perlseeker19 has asked for the wisdom of the Perl Monks concerning the following question:

thank you one and all for your timely guidance

i have given @cat=qw(cmd),gave a set of commands and now able to achieve what that had been done using expect.pm"

i now would require ur suggestions and guidance on playing around with timers

there are two questions here

1.i have to jus throw an exception when the timeout occurs

2.when i pump for eg...

$h = start /@cmd, /$in ,/$out; $in .= "some command"; pump $h until $out=~/some desired string/i;

i need to restart or atleast display an error message when the desired string is not got.

i have also seen an implementation $t = timeout(10); $h=start /@cmd, /$in ,/$out; this is to give 10 seconds of time for @cat to start,

$in.="some command"; $t->time(5);
this seems to be the response time,but gives an error cannot access object time through IPC::Run::Timer,

help me in this regard thanks

Replies are listed 'Best First'.
Re: using IPC::Run
by jethro (Monsignor) on Jul 29, 2008 at 12:56 UTC
    IPC::Run runs commands on the command line, feeds them (like Expect) lines on stdin and fetches the output of the program.

    The first parameter of your start call (in your case @cat) should contain the program you wish to call. If you don't give IPC::Run anything to run, it naturally sees no sense in running.

    If you give it a program to run that uses a GUI instead of a command line (don't know, but Edit sounds like it might use a GUI) it also might have problems running

    "Process ended prematurely" probably means the program you called (i.e. Edit) stopped running before it could receive any of the input you provided.

      hi jethro,

      thank you for your valuable idea.my requirement is to run a command prompt.go to a particular directory and run a command.

      during execution of this command i wait for a particular string to occur. the moment it occurs i will have to open a com port.the comport part is ready

      now that i have changed @cat = qw(cmd). i get

      "IPC::Run: timeout on timer #1 at C:/Perl/site/lib/IPC/Run.pm line 2932

      please help me out

Re: using IPC::Run
by Anonymous Monk on Jul 29, 2008 at 12:00 UTC
    Why is that a suprise, after all @cat is undefined?
    use strict; use warning;

      so what should i be doing?? with @cat now, can you just brief on the purpose of @cat here in the code.

      like i have used @cat =qw(Edit);

      since i am using activeperl.(running scripts using command prompt).

      while running i get the error "process ended prematurely" pointing the line containing "pump" after the first input

        Well, why should we know what @cat is supposed to contain? You wrote the program, so you have to tell us what it should do. Maybe consider re-reading IPC::Run?

        What do you think @cat = qw(Edit) is doing? What purpose does that have?

Re: using IPC::Run
by FunkyMonk (Bishop) on Jul 29, 2008 at 22:22 UTC
    $in ="c:\n"; isn't doing what you think it is. Inside a doubly-quoted string, \n is interpreted as a newline character. I think you probably meant $in ="c:\\n";.

    Unless I state otherwise, all my code runs with strict and warnings