Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: How to send Ctrl^C to a program via Expect module

by beable (Friar)
on Jul 23, 2004 at 06:47 UTC ( #376816=note: print w/replies, xml ) Need Help??


in reply to How to send Ctrl^C to a program via Expect module

You should use the soft_close() or hard_close() methods. Please take a look at the documentation for the Expect module. Here's a simple example:

#!/usr/bin/perl use strict; use warnings; use Expect; my $command = "cat > tmp.txt"; my @params; my $exp = Expect->spawn($command, @params) or die "Cannot spawn $command: $!\n"; print("sending...\n"); $exp->send("Hello world\n"); sleep 1; $exp->hard_close; __END__

Or, if you really want to send Ctrl-C to your process, try this: $exp->send("\cC");. Or you can just send a signal to the process like Fletch recommends.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://376816]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2023-04-02 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?