goexpect icon indicating copy to clipboard operation
goexpect copied to clipboard

How to send 'Ctrl-C' to the interactive shell spawned by SpawnWithArgs

Open fangxlmr opened this issue 4 years ago • 2 comments

Say, I run cat /proc/kmsg as a root user on the interfactive SSH shell spawned by SpawnWithArgs, but it will hangs for ever (since you wouldn't cat anything from the magic file /proc/kmsg even as root), so no following commands sent to this SSH shell will not be executed by the SSH shell since it is haning on. I'd like invoke Ctrl-C in this SSH shell spawned by goexpect to stop cat progress clearing the shell, just like what we will do in an actual one.

I've tried

  1. sending ASCII code \003 (by calling exp.Write()) wouldn't work.
  2. SendSignal batcher seems send signals to the SSH progress itself, not she SHELL inside the SSH session.

Are there any ways to do this? What did I miss here?

fangxlmr avatar Mar 24 '21 11:03 fangxlmr

CC @skalle

fangxlmr avatar Mar 24 '21 11:03 fangxlmr

As posted here, I don't think it's possible and portable to send a 'Ctrl-C' signal to remote SHELL in SSH session.

Sending a simple '\x03' surely wouldn't work since most of SSH server/client doesn't support signal messages. I'm not sure how expect is implemented, but it should behavior the same way. However, some posts also said sending \x03 works fine in expect scripts, so I'm a bit confused. :-

fangxlmr avatar Mar 29 '21 05:03 fangxlmr