Expect shell can not working well in Jenkins pipeline

I had an expect shell just like below:

spawn pnpm changeset
expect {
*changed packages* {
  send " \r"
}
}
interact

because the command pnpm changeset will list some packages to be select by space key or enter key,so it can be instead by " " and “\r”

this script is working well in Linux bash

but when I call it in jenkins, it didn’t work, nothing to output and just waiting for timeout !

somebody can help me?