Passing a command to a process that's already running

Discussion in 'Perl Misc' started by Keith, Sep 20, 2005.

  1. Keith

    Keith Guest

    I want to be able to use perl to open a program and then pass a command
    to it.

    The program is links which is a text-based browser. After openning a
    webpage I want to be able to pass a command to the browser. What perl
    command do I use in this case?

    If I use exec("links www.foo.org") to open the links browser, I can't
    pass a command to it since the script stops working.

    If I use system(("links www.foo.org") the perl script stops and I
    cannot progress forward until I manually close the links applicatioon.


    Any help here?
     
    Keith, Sep 20, 2005
    #1
    1. Advertising

  2. Keith wrote:
    > I want to be able to use perl to open a program and then pass a command
    > to it.
    >
    > The program is links which is a text-based browser. After openning a
    > webpage I want to be able to pass a command to the browser. What perl
    > command do I use in this case?
    >
    > If I use exec("links www.foo.org") to open the links browser, I can't
    > pass a command to it since the script stops working.
    >
    > If I use system(("links www.foo.org") the perl script stops and I
    > cannot progress forward until I manually close the links applicatioon.
    >
    >
    > Any help here?


    You might want to look at "expect". Originally built on top of Tcl,
    there is a perl implementation. See CPAN for details.

    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett
     
    Josef Moellers, Sep 20, 2005
    #2
    1. Advertising

  3. Keith

    Anno Siegel Guest

    Keith <> wrote in comp.lang.perl.misc:
    > I want to be able to use perl to open a program and then pass a command
    > to it.
    >
    > The program is links which is a text-based browser. After openning a
    > webpage I want to be able to pass a command to the browser. What perl
    > command do I use in this case?
    >
    > If I use exec("links www.foo.org") to open the links browser, I can't
    > pass a command to it since the script stops working.
    >
    > If I use system(("links www.foo.org") the perl script stops and I
    > cannot progress forward until I manually close the links applicatioon.
    >
    >
    > Any help here?


    open my $links, '| links' or die "links process start: $!";
    print $links 'retrieve something';
    print $links 'other command';
    close $links or die "links process exit: $?";

    See perldoc open.

    Anno
    --
    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.
     
    Anno Siegel, Sep 20, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jona
    Replies:
    2
    Views:
    839
  2. John English
    Replies:
    0
    Views:
    5,287
    John English
    Nov 7, 2005
  3. .rhavin grobert

    pipe to an already running process?

    .rhavin grobert, Jan 8, 2006, in forum: Perl Misc
    Replies:
    0
    Views:
    146
    .rhavin grobert
    Jan 8, 2006
  4. .rhavin grobert

    pipe possible to an already running process?

    .rhavin grobert, Jan 8, 2006, in forum: Perl Misc
    Replies:
    2
    Views:
    130
    Bodo Eing
    Jan 9, 2006
  5. Victor Hooi
    Replies:
    1
    Views:
    158
    Nobody
    Feb 10, 2013
Loading...

Share This Page