From: <li...@jo...> - 2007-10-27 12:48:06
|
<p><br />Hi all,<br /><br />Sorry this is so long and vague (I'll try to co= de up a small example because my little project uses a back-end database an= d I'd like to split the Expect piece out - this will take a while). F= or anyone who's interested have a look at the March 2007 thread to see the = solution to my original problem.<br /><br />My new code (below) no longer w= orks (I've done a lot of code changes and need to backtrack to see what exa= ctly broke it). In the meantime I'm wondering if there's a better way= .<br /><br />Here's what I'm trying to do...<br />1. Match and capture a pr= ompt at the start of a line.<br /> This works perfectly (March = 2007 code)<br />2. Look up the matched prompt and see if it...<br /> &= nbsp; (a) needs a response,<br /> (b) c= an be ignored, or,<br /> (c) needs special handling= .<br /> Always works.<br />3a. For "normal" prompt se= nd response + "\r" and exp_continue for next prompt.<br />3b. For= "ignored" prompt just exp_continue.<br />3c. For a "special= " prompt sleep 3 seconds then check if there's any more output, if the= re 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.<br /><br />= <br />Case 3c isn't working. When I do it manually I get this...<br /= ><br />NORMAL_PROMPT_1 (I send response= + "\r")<br />NORMAL_PROMPT_2 = (I send response + "\r")<br />SPECIAL_PROMPT_1 NO (I= see "NO" straight away and do nothing)<br />SPECIAL_PROMPT_2&nbs= p; (I send response + "\r" as input requi= red)<br />NORMAL_PROMPT_3 (I send respo= nse + "\r")<br />...<br /><br /><br />When scripted this ha= ppens...<br /><br />NORMAL_PROMPT_1 (script s= ends response + "\r")<br />NORMAL_PROMPT_2  = ; (script sends response + "\r")<br />SPECIAL_PROMPT_1 = ; (sleep 3 seconds)<br /> &n= bsp;  = ; (don't see further output so send response + \r)<br /> &= nbsp; &nbs= p; print debug message to terminal &quo= t;*sending*"<br /> &nbs= p; Then I= get NO from the remote printed on the screen<br /><br />So it looks like..= .<br /><br />NORMAL_PROMPT_1 RESPONSE_1\r<br />NORMAL_PRO= MPT_2 RESPONSE_2\r<br />SPECIAL_PROMPT_1 RESP= ONSE_3\r *sending*<br />NO &= nbsp; (the \r sent above fo= rces a newline here even if response is "")<br />NORMAL_PROMPT_3&= nbsp; remote assumes RESPONSE_3 + \r is for this.<br /> &n= bsp;  = ; Wrong :-(<br /><br /><br />It seems that after se= nding "response\r" the accumulator suddenly gets the NO from the = remote system but that's after the script thinks it has to send a response.= Kermit may be the problem as it's driving the link (either serial or= via telnet) and it may be buffering (I don't think so as it works OK manua= lly)<br /><br /><br />Is there a way to check if I need to send a response = without having to actually send it?<br /><br />I've tried combinations of<b= r />buffer =3D exp->after()<br />and<br />buffer =3D clear_accum(); set_= accum($buffer)<br />but no joy.</p><p> </p><p>Is there a way to check = for further characters without absorbing them (because that text could be m= y next prompt and I need to keep that in the accumulator for the next pass = of expect)<br /><br />Thanks,<br />John.<br /><br /> =0D </p><BR> |