From: markgo <gol...@gm...> - 2007-07-05 07:26:21
|
Hi, In some script I'm sending the command that runs some tool that could only be stopped by pressing Ctrl-C. It does not wait for any input. Is there any way to simulate this Ctrl-C (that is SIGINT) except closing the session? Currently it looks like that: $session = new Expect; $session->spawn("su - $user_name") or die "..."; # Script runs as root $session->expect(....); ... $session->send("sudo $tool"); ... This is a tool I'd like to interrupt. $session->send("\cC") does not work, I suppose because the tool is not waiting for input. Thank you, Mark -- View this message in context: http://www.nabble.com/Is-it-possible-to-interrupt-spawned-session-%28like-Ctrl-C%29-tf4028111.html#a11441982 Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. |
From: Ken I. <fn...@ua...> - 2007-07-06 14:51:34
|
On Thu, Jul 05, 2007 at 12:26:20AM -0700, markgo wrote: > > Hi, > > In some script I'm sending the command that runs some tool that could only > be stopped by pressing Ctrl-C. It does not wait for any input. Is there any > way to simulate this Ctrl-C (that is SIGINT) except closing the session? > > Currently it looks like that: > > $session = new Expect; > $session->spawn("su - $user_name") or die "..."; # Script runs as root > $session->expect(....); > ... > > $session->send("sudo $tool"); > > ... > > This is a tool I'd like to interrupt. > > $session->send("\cC") does not work, I suppose because the tool is not > waiting for input. > > Thank you, > Mark Why not just send the signal directly to the process: kill SIGINT $tool_pid; Ken -- Ken Irving, fn...@ua... |
From: Bruno N. <bn...@gm...> - 2007-07-06 14:59:38
|
Why don't you add a signal handler to your perl script that when it receives the CTRL-C it calls the $exp->hard_close(); on the spawned expect object? regards, bruno On 7/6/07, Ken Irving <fn...@ua...> wrote: > On Thu, Jul 05, 2007 at 12:26:20AM -0700, markgo wrote: > > > > Hi, > > > > In some script I'm sending the command that runs some tool that could only > > be stopped by pressing Ctrl-C. It does not wait for any input. Is there any > > way to simulate this Ctrl-C (that is SIGINT) except closing the session? > > > > Currently it looks like that: > > > > $session = new Expect; > > $session->spawn("su - $user_name") or die "..."; # Script runs as root > > $session->expect(....); > > ... > > > > $session->send("sudo $tool"); > > > > ... > > > > This is a tool I'd like to interrupt. > > > > $session->send("\cC") does not work, I suppose because the tool is not > > waiting for input. > > > > Thank you, > > Mark > > Why not just send the signal directly to the process: > > kill SIGINT $tool_pid; > > Ken > > -- > Ken Irving, fn...@ua... > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |
From: markgo <gol...@gm...> - 2007-07-06 18:59:17
|
Bruno Negrao-3 wrote: > > Why don't you add a signal handler to your perl script that when it > receives the CTRL-C > it calls the > > $exp->hard_close(); > > on the spawned expect object? > > regards, > > bruno > > Thanks for your response, but the situation is a bit different. I'm testing someone's tool. I can't modify it. I actually need to kill some of its sub-processes. Ken's suggestion works fine. -- View this message in context: http://www.nabble.com/Is-it-possible-to-interrupt-spawned-session-%28like-Ctrl-C%29-tf4028111.html#a11470788 Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. |
From: markgo <gol...@gm...> - 2007-07-06 18:55:20
|
Ken Irving wrote: > > On Thu, Jul 05, 2007 at 12:26:20AM -0700, markgo wrote: >> >> Hi, >> >> In some script I'm sending the command that runs some tool that could >> only >> be stopped by pressing Ctrl-C. It does not wait for any input. Is there >> any >> way to simulate this Ctrl-C (that is SIGINT) except closing the session? > Why not just send the signal directly to the process: > > kill SIGINT $tool_pid; > > Ken > > Indeed! Silly me. The tool printed out "press Ctrl-C" and I tried to send Ctrl-C. Thank you Ken, of course it works that way. -- View this message in context: http://www.nabble.com/Is-it-possible-to-interrupt-spawned-session-%28like-Ctrl-C%29-tf4028111.html#a11470738 Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. |
From: Austin S. <te...@of...> - 2007-07-06 17:16:03
|
> This is a tool I'd like to interrupt. > > $session->send("\cC") does not work, I suppose because the tool is not > waiting for input. > It should work anyway unless you have tweaked your term settings interrupt character. $session->slave->stty('intr', "\cC") should do it. Austin |
From: markgo <gol...@gm...> - 2007-07-06 19:02:18
|
Austin Schutz wrote: > >> This is a tool I'd like to interrupt. >> >> $session->send("\cC") does not work, I suppose because the tool is not >> waiting for input. >> > > It should work anyway unless you have tweaked your term settings > interrupt character. $session->slave->stty('intr', "\cC") should do it. > > > Austin > Thanks for advice, I'll try to understand it better (it di dnot work as I expected). Actually, Ken's suggestion solved my problem. -- View this message in context: http://www.nabble.com/Is-it-possible-to-interrupt-spawned-session-%28like-Ctrl-C%29-tf4028111.html#a11470791 Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. |