0

I have an expect script that is working if I pass it in a negative number. However, it will now not accept positive numbers. The values I am trying to pass are -12345 and 12345. Here is my script:

spawn -noecho $servicecode --enable
expect "Do you want to continue*" { send "y\n" }
expect "password:" { send "${password}\n" }
expect "passcode:" { send -- "${passcode}\n" }
expect "*Service has been successfully enabled*"
expect eof
EOF

Now, if I remove the "--" from the expect statement, it now accepts positive integers but will no longer accept negative integers. If I put back the "--", it accepts negative numbers but now not positive numbers.

Can anyone help me in figuring out how to send both positive and negative integers?

oguz ismail
  • 1
  • 16
  • 47
  • 69
jberthia
  • 111
  • 7
  • `expect -d /your/script.exp ...` and see what's happening. – pynexj Apr 03 '20 at 12:14
  • What exactly happens with positive integers when you use `--`? – chepner Apr 03 '20 at 12:33
  • Tcl sees `send "-9\r"` as an option, not a value. Same thing happens in the shell, it's very difficult to get `echo` to print the string "-n". Just make it a habit to always use `send -- ...`, but especially when you're dealing with user input (like passwords) – glenn jackman Apr 03 '20 at 16:13
  • @glennjackman, it's Expect's `send` who sees `-9\r` as an option, not Tcl. – pynexj Apr 04 '20 at 17:24

0 Answers0