Expect - Interrupt program - Ctrl+C

前端 未结 1 521
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-06 03:04

I am running the following script to start a capture on a remote server and download the file afterwards. Currently I have to pause it with Ctrl+C and manu

1条回答
  •  别跟我提以往
    2021-02-06 03:18

    To send a Ctrl+C, do:

    send \x03
    

    To handle an incoming Ctrl+C, do:

    trap {your handler script here} SIGINT
    

    You might want to make the handler script (which can be a multi-line thing) send the signal on to the inner process…

    trap {
        send \x03
        send_user "You pressed Ctrl+C\n"
    } SIGINT
    

    But take care! When the user presses Ctrl+C in a text-mode program (in most GUIs, it's a copy action) they are usually expecting it to go away pretty soon, so you should take care to ensure that you don't spend too long after the signal arrives cleaning everything up.

    0 讨论(0)
提交回复
热议问题