Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ANSI and no ANSI text with WHEN or WaitFor

Status
Not open for further replies.

JGoudie

Programmer
Jun 17, 2002
16
0
0
CA
Hi there, i just purchased procomm earlier today and was playing with the scripting part. I found that procomm matches strings fine if ansi is turned off, but if the incoming data contain ansi sequences and stuff (colors) it doesn't catch them in when or waitfor statements.

Is there a way around this?

actually what i found was if the incoming text contain multiple colors and you are trying to wait for a few words and say they are different colors.

eg)
Blue Cat strolls down the road

Blue would be blue, and Cat would be red. If you wait for Blue Cat, it won't show up if ANSI is on. But if you turn ansi off it works. I want to know if there is a easy way to strip the ansi characters so that the waitfors and whens will work no matter if you are viewing colors or not

Thank You
James

 
Waitfor and when are looking for an exact match with their target string, so you cannot search for that exact string if there is the possibility of text appearing different colors (thus different escape sequences in the received string). I suppose that you want the colors to still appear, so switching ANSI off is not a true option? If so, then I'm aware of a suitable workaround.

You could use then when target command with the strip argument to delete the escape sequence from Procomm's receive buffer (you would need a separate when target command for each color escape sequence). However, this would keep "blue" from appearing in blue and "cat" from appearing in red.

You could use something like the following code to possibly workaround this problem, but it does not guarantee that you are targeting on "blue cat" instead of "blue fat cat" instead:

waitfor "blue"
if sucess
waitfor "cat" 1
if success
do necessary operations
endif
endif

This code would search for the word "cat" for one second after the word "blue" had been found. Possibly a better way to do this would be to use the when target command to wait for the word "blue" to appear, and then in the called procedure, use the waitfor "cat" 1 command. This would work a little better since you would not have to worry about the waitfor "blue" command timing out.

One final option is looking at the termgets or termreads command and see if that works better for your particular situation.
 
There is an easy work-around if the colors are always the same (Blue is always blue and Cat is always Red). I have done similar scripting with an ANSI emulation.

Determine what control characters the host is sending to set the colors, then include the hidden characters in your When Target or Waitfor commands. You can find them by recording the manual script process and reviewing the waitfor prompts. The control characters will have brackets and numerical codes right before "Blue" and "Cat." Test it a few times by recording your script to make sure you are using a consistent character prompt.

Another work-around is the "waitquiet" command, provided your host system is waiting for a response from the script or user before sending additional data. I use "waitquiet" instead of "pause XX" and "waitfor XX seconds" whenever possible so that proper script execution is not dependent on a predetermined time duration. Robert Harris
Communications Advantage
 
thanks a bunch guys. i will give it try. i like the idea of waiting for the text with the ansi codes in it.

thank you again guys
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top