1

I am trying to kill a local background process at a certain point in an expect script. Consider the sample script:

#! /usr/bin/expect
set killPID [lindex $argv 0];
set timeout 1
spawn ftp ftp.ftp.com
expect "Name"
send "Username\r"
expect "Password:"
send "xxxxxx\r"
expect "ftp>"
send_user "Killing local process id: $killPID\n"
interact

I run this script with the id of a local process that I want to kill as first argument. How can I kill the process just before the interact command?

Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174
  • You can first kill the process in the script and then perform expect. That looks easy, if you don't have tight requirements. – Vishal R Apr 07 '14 at 11:37
  • @vishram0709 Thanks, but this is just a sample to illustrate. The actual script is more complicated. So I need to kill it inside the expect script. In general, I am asking how to execute a local command (like `kill $killPID`) from within an expect script. – Håkon Hægland Apr 07 '14 at 11:39

1 Answers1

3

To run a command on the local machine that requires no interaction, do:

exec kill $killPID
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
  • Things get much more complex if you want to do things remotely or if you want to interact with two subprocesses at once. You definitely _can_ but it isn't as simple by far. – Donal Fellows Apr 07 '14 at 12:25