Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking for a sample code that can issue ctrl-C in perl 1

Status
Not open for further replies.

whn

Programmer
Oct 14, 2007
265
US
As stated in the subjuct.

Thank you very much for your help.
 
A Ctrl-C sends a control character with hex 0x03 (I figured that from a quick Google search:
So

Code:
print "\x03";

or

print chr(0x03);

That'd print the Ctrl-C character to your terminal (in my terminal it showed up as an odd triangle character).

Code:
[kirsle@firefly ~]$ perl
print "Gonna send Ctrl-C\n";
print "\x03";
print "Sent it.\n";
__END__
Gonna send Ctrl-C
Sent it.

It won't abort the currently running script as though the user typed Ctrl-C (if you want that, just exit() :p), but if you were interacting with a program that needs to receive Ctrl-C, that's how you'd do it (i.e. print it to a filehandle or named pipe or something instead of the terminal, STDOUT).

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top