Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ Accessing mud output
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Khorlane
(2 posts) Bio
|
| Date
| Wed 12 Sep 2001 12:00 PM (UTC) |
| Message
| I need to access the results of a mud command. The result of this command could be 1 to n lines, each of which is identical the previous except for a 'count' value. Here's an example:
Comand:
where smallrat
Result:
M 1. a small rat - [ 184] North Way
M 2. a small rat - [ 186] Jesse Square
M 3. a small rat - [ 103] West Way
M 4. a small rat - [ 126] Adam Street
M 5. a small rat - [ 186] Jesse Square
M 6. a small rat - [ 103] West Way
M 7. a small rat - [ 103] West Way
I need to parse the last line of the result. Is there any way to accomplish this without writing the log to a text file and then reading the captured log text file?
| | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Thu 13 Sep 2001 12:52 AM (UTC) |
| Message
| I think you can do that OK with triggers. The main problem is to know which is the last line, as I gather you won't know in advance if it is 7 lines or 20.
However you would have exactly the same problem with writing to a file and reading it back in - you need to know when to do that.
I would make a trigger that matches on the result lines, eg. something like:
^M \d+\. (.*?)$
This trigger could call a script, or simply send %1 to a variable (for later use).
Then have a second trigger that matches whatever it is that tells you that the list has ended.
Then in the second trigger you retrieve the results of the variable and parse it.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Khorlane
(2 posts) Bio
|
| Date
| Reply #2 on Thu 13 Sep 2001 01:41 AM (UTC) |
| Message
| Yes indeed, the list is of unknown length and nothing stands out as an 'end of list' indication. So, the second trigger is a problem ... maybe it could be a 'oneshot' timer set to fire after 5 seconds. The 5 seconds is more than enough time for the "where smallrat" command to finish.
Possible Trigger Solution:
Set up trigger:
^M \d+\. (.*?)$ to save %1 in a variable
vbscript: pseudo code: Script1
World.send "where smallrat"
-- 1st trigger saves line in variable for later use.
-- oneshot timmer to wait 5 seconds for "where smallrat" to finish, then executes Script2 to examine variable.
World.addtimer "my_timer", 0, 0, 5, "", 5, "Script2"
Also, would this work?
Possible Log Capture Solution:
vbscript:
World.openlog "mylog.txt", false
World.send "where smallrat"
World.closelog
-- code here to open, read, parse, close mylog.txt --
Thanks for your help.
Steve | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #3 on Thu 13 Sep 2001 04:00 AM (UTC) |
| Message
| The timer might work but sounds a bit wonky - it might fail if the server was slow.
I would do something like this:
- Activate a trigger to match on "M <number> ..."
- When the first trigger fires (for the first time - you could use a counter) activate a second trigger to match on everything (eg. "*")
- In the second trigger, when a line arrives that doesn't start with "M <number>" you know you have reached the end of the list.
Or perhaps more simply, just have one trigger that matches on everything (ie. "*"). In it you simply look for "M <number>". You could count them. Once the number of them is one or more, and a line arrives that doesn't start with "M" you know that the previous line was the last one (which you saved in a variable).
Quote:
World.openlog "mylog.txt", false
World.send "where smallrat"
World.closelog
This won't work because it would send "where smallrat" and immediately close the log. You need to pause for an unknown time to wait for the output to arrive. I think my trigger solution would work better.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
15,295 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top