From: John B. (Lists) <li...@jo...> - 2007-10-25 21:49:20
|
Hi all, Sorry this is so long and vague (I'll try to code up a small example because my little project uses a variable regexp and matchlist to extract the matched prompt). For anyone who's interested have a look at the mailing list for March 2007 for Roland's very elegant solution. My workaround for the new problem below no longer works (I've done a lot of code changes and need to backtrack to see what broke it). In the meantime I'm wondering if there's a better way. Here's what I'm trying to do... 1. Match a prompt at the start of a line and capture it and any trailing spaces - this works perfectly (March 2007 code) 2. Look up the matched prompt and see if it needs a response, can be ignored or needs special handling. Always works. 3a. For "normal" prompt send response + "\r" and exp_continue for next prompt 3b. For "ignored" prompt just exp_continue (remote system displays next prompt automatically so pick it up on the next pass of expect) 3c. For a "special" prompt sleep 3 seconds then check if there's any more output, if there is the script shouldn't send a response because the remote system is telling me the status of this setting as opposed to asking for input. If will then present the next prompt (i.e. case 3b above). But if there's no further output it's a request for input and so a response must be given (even if just "\r"). Case 3c isn't working. When I do it manually I get this... NORMAL_PROMPT_1 (I send response + "\r") NORMAL_PROMPT_2 (I send response + "\r") SPECIAL_PROMPT_1 NO (I see "NO" straight away and do nothing) SPECIAL_PROMPT_2 (I send response + "\r" as input required) NORMAL_PROMPT_3 (I send response + "\r") ... When I script it here's what happens... NORMAL_PROMPT_1 (script sends response + "\r") NORMAL_PROMPT_2 (script sends response + "\r") SPECIAL_PROMPT_1 (sleep 3 seconds) (don't see further output so send response + \r) print debug message to terminal "*sending*" Then I get NO to the screen from the remote So it looks like... NORMAL_PROMPT_1 RESPONSE_1\r NORMAL_PROMPT_2 RESPONSE_2\r SPECIAL_PROMPT_1 RESPONSE_3\r *sending* NO (not the \r sent above forces a newline here) NORMAL_PROMPT_3 remote assumes RESPONSE_3 + \r is for this. Wrong :-( What seems to be happening is after sending response + "\r" the accumulator suddenly gets the NO from the remote system but that's after I check if I need a response. Is there a way to check if I need to send a response without having to actually send it? I've tried combinations of exp->after() and clear_accum()/set_accum() but no joy. Is there a way to check for further characters without absorbing them (because that text could be my next prompt and I need to keep that in the accumulator for the next pass of expect) Thanks, John. |