From: John B. (Lists) <li...@jo...> - 2007-10-26 23:20:16
|
Hi all, Sorry this is so long and vague (I'll try to code up a small example because my little project uses a back-end database and I'd like to split the Expect piece out - this will take a while). For anyone who's interested have a look at the March 2007 thread to see Roland's very elegant solution to my original problem. My new code (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 and capture a prompt at the start of a line. This works perfectly (March 2007 code) 2. Look up the matched prompt and see if it... (a) needs a response, (b) can be ignored, or, (c) 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. 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 showing the status of this setting as opposed to asking for input. It will then present the next prompt (i.e. treat this prompt as in 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") as in 3b. 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 from the remote printed on the screen 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. |