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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

termgets question

Status
Not open for further replies.

BugMan1400

Technical User
Dec 8, 2004
3
0
0
US
I have a remote device that returns the following after I send it the appropriate command:

1.) Apple
2.) Orange
3.) Bananna
4.) Grape

What I would like to find out is what number 'Orange' is on. In this example, it would be line #2, but the remote device could return 'Orange' on any line. Any ideas?

Mucho thanks!
 
Will the 4 choices always be on the same lines? Will there always be 4 choices?

The reason I ask is because there are a few ways to go about this.

You could tell your script to waitfor "1.)" and then save the rest of the line to a variable called (something like) "sVar1". And repeat for each new number, afterword you would do a strfind on each variable to find the orange.

That is one way.

Or you could wait until all the choices come out, and assuming there are the same number of choices each time, and you knew which rows of the terminal the choices would land on, you could save each line of the terminal that has choices on them to seperate variables, and search each one, and upon finding it, you would then search for each number (1,2,3,4) on that line to see which one catches.

Additionally, you could waitfor "oranges" and capture the next 4 characters to see which number you grab, and subtract 1 from it for your orange.

Without more specific information as to what the prompts before and after may look like, it would be impossible to show you some easy example code that could complete this using any of the processes I described above.

Would you care to elaborate a little more? Maybe a cut and paste?

Brandon
 
The way I would probably do it is to use the snapshot command to save the screen to a file, open the file using fopen, and read it line by line using fgets (I think I have an example on my site of doing this part). Use the strfind command to check each line for "Orange." Once you have that, you could use the strextract command or several other string commands to pull off the first character of that line, which should be the number.

 
This has given me several options I did not think of. All seem like they would actually work.

My initial thought was to search for 'Orange' and try to termgets the line, but I couldn't figure out how to retrieve the Row or Line. My list choices could be variable; anywhere from 4 to 20. Also, there may be extra terminal dialog before the list choice (i.e. logon, dialup, menus, etc.). The fruit list 1 thru 4 was just an example, but represents my application. Like I said before the fruit list could be in any order and be as much as 20 items long.

Thanks!!!
 
I don't see where you solved your problem.. So let me ask a question - and present an option. You only show a small piece of the response. What comes out AFTER the fruits ? What I often do is turn the capture to file on just before the output I want to interrogate. Then when it is complete turn the capture off.

Then I only need to read the capture files (ie Find the word orange) and the beginning of the line up to the ".)" is the line number.
 
I ended up going with knob's option. It seems simple and has worked for me so far. I was also able to use the 'sbsave' command as way to document the communication. Thanks knob!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top