mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
Get mIRC to watch text file and dump text live #222970 11/07/10 04:22 AM
Joined: Jul 2010
Posts: 2
J
JoshGamJaffa Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
J
Joined: Jul 2010
Posts: 2
Hi All,

My first post so please bare with me...

I am trying to get mIRC to watch a .txt file that is constantly getting written to by a paging receiver application. I am after a script or line of text I can use to extract/watch a .txt file and dump it live to a channel.

There are two possible ways to do this:

Script to watch .txt and dump lines as they are updated by another application

The paging decoder program "PDW" is able to run a .bat file with arguments. Is there a way to get a bat file enter text into an already opened channel as each message enters?

I hope this isn't to confusing. Any questions please ask. I am very eager to get this working asap but an exhausted my searching ability on the net.

Thanks in advance.

Cheers!

Re: Get mIRC to watch text file and dump text live [Re: JoshGamJaffa] #222972 11/07/10 05:18 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
My recommendation for sending the contents of a text file to a pm/query or channel window, is to use mIRC's /play command.

With mIRC 6.35, type /help /play
then choose the 2nd /play option

Re: Get mIRC to watch text file and dump text live [Re: RusselB] #222978 11/07/10 11:07 AM
Joined: Jul 2010
Posts: 2
J
JoshGamJaffa Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
J
Joined: Jul 2010
Posts: 2
Hi RussleB,

Thanks for your quick response.

We have tried using the /play command but it doesn't check for 'new' data in the text file. It just 'plays whole text file' and not just 'new' data in the text file.

I know this is a weird thing but it would be awesome if someone had ANYTHING close to what we are after.

Thanks in advance.

Cheers,
Josh

Re: Get mIRC to watch text file and dump text live [Re: JoshGamJaffa] #222979 11/07/10 11:26 AM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
if the application is not able to send mIRC any indication of having written to the file (incorporating a DLL that triggers events or otherwise) then you'll have to poll the file periodically to check if it's changed. there are several ways of detecting a change in a file, an efficient method being to compare $file().mtime to see if the value returned differs from what it was previously. of course, a change there might not necessarily imply a change in the file's contents, it's possible that an external process wrote to the file and then removed what it wrote. this might not apply to your case in particular, but it's something worth considering in general

other checks involve examining the data that makes up the file, such as comparing $crc() or $md5() before and after results, but these run slower than checking $file().mtime which might be a crucial distinction if you plan to perform this check every second or so.


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Re: Get mIRC to watch text file and dump text live [Re: JoshGamJaffa] #222986 11/07/10 02:35 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
If it is only ADDING lines to the file, you can check the $lines and if it's greater than the last check (stored as a variable), then display the new lines. That won't work if it's removing lines or changing lines.


Invision Support
#Invision on irc.irchighway.net
Re: Get mIRC to watch text file and dump text live [Re: jaytea] #223176 16/07/10 11:13 PM
Joined: Sep 2009
Posts: 52
Z
ziv Offline
Babel fish
Offline
Babel fish
Z
Joined: Sep 2009
Posts: 52
Any check of whether the file changed or not would be pointless, since you gotta find out what changed anyways.
You might as well go right away and scan the file for the changes.

Code:
alias txt_crc {
  var %file1 = <enter filename here>
  var %file2 = Backup.txt
  var %i = 1
  while %i <= $lines(%file) {
    if $read(%file1,%i) != $read(%file2,%i) {
      write $+(-l,%i) %file2 $read(%file1,%i)
      .msg <channel> $read(file1,%i)
    }
    inc %i
  }
}


This alias can be triggered manually, or used with a timer.
A note on this is that this check can take a while if the file is long!
If you set it to run every couple of seconds, be ready for mIRC getting frozen.

Good luck,
ziv.

Re: Get mIRC to watch text file and dump text live [Re: ziv] #223181 17/07/10 04:01 AM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
Originally Posted By: ziv
Any check of whether the file changed or not would be pointless, since you gotta find out what changed anyways.
You might as well go right away and scan the file for the changes.


that is extremely illadvised, a very quick and simple check such as $file().mtime is certainly not pointless as you save mIRC the trouble of having to load a potentially large file into memory and 'scan' it or otherwise when it doesn't have to. if this check is performed even slightly more often than the file is modified, it should be employed. consider what would happen if the external application was such that it added lines to the end of the file, on average, every 30 seconds (it is a paging application after all). what you're advocating will traverse the file line by line with the notoriously slow $read() until it either reaches the end or finds a line change. now imagine this being done on a significantly sized file every second (or however often the OP deems suitable), resulting in an unnecessarily intensive check an average of 29 out of 30 times.

that is why simple checks such as those on $file().mtime are valuable, it allows you to abandon the operation and save yourself extra unnecessary overhead on a good portion of thse checks. then, if the mtime has changed, we can go forward with a more thorough test such as the one you described (though preferably with file handling commands or such)


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Re: Get mIRC to watch text file and dump text live [Re: jaytea] #223184 17/07/10 06:04 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Additionally, if the file was of sufficient size, due to the slowness of $read, it could take longer to check the file for changes than the delay the OP wants.

Re: Get mIRC to watch text file and dump text live [Re: RusselB] #223239 19/07/10 04:51 PM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline
Fjord artisan
Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
Originally Posted By: RusselB
Additionally, if the file was of sufficient size, due to the slowness of $read, it could take longer to check the file for changes than the delay the OP wants.


/fseek <handle> <pos>!

Do you people know ANYTHING about file handles at all? AT ALL? I find it SO frustrating people don't understand what is truly a basic concept. Only with mIRC users too can't seem to grasp this.

Okat okay... i understand it's not so basic. Give me a sec i'll write an alias that shows how to use it.

In the meantime, look at this post as it holds the key...

Last edited by MeStinkBAD; 19/07/10 05:15 PM.

Beware of MeStinkBAD! He knows more than he actually does!
Re: Get mIRC to watch text file and dump text live [Re: MeStinkBAD] #223244 19/07/10 05:34 PM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline
Fjord artisan
Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
Code:
alias filetest {
  if (%filetest.lastfpos !isnum) {
    set %filetest.lastfpos 0
  }
  
  .fopen filetest $1-
  
  if (!$ferr) {
    /fseek filetest %filetest.lastfpos
  }
  
  while (!$feof && !$ferr) {
    /echo $fread(filetest)
  }
  
  set %filetest.lastfpos $fopen(filetest).pos
  
  .fclose filetest
  
  return
  
  :error
  if (*command halted* iswm $error) {
    if ($fopen(filetest)) .fclose $v1
  }
}


There try that...


Beware of MeStinkBAD! He knows more than he actually does!
Re: Get mIRC to watch text file and dump text live [Re: MeStinkBAD] #223249 19/07/10 07:39 PM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Yet, as you fopen a file to check for changes, mIRCs file handling might prevent that other app to access the file and do the very changes you're looking for...

Re: Get mIRC to watch text file and dump text live [Re: Horstl] #223252 19/07/10 08:18 PM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline
Fjord artisan
Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
Originally Posted By: Horstl
Yet, as you fopen a file to check for changes, mIRCs file handling might prevent that other app to access the file and do the very changes you're looking for...


It closes access to file the file when done. It does not keep the file open when it doesn't need to. Please be realistic. The amount of time the file will be open is but milliseconds.

And it'a not my fault mIRC opens every file with write access. I've asked for read-only access with this command. I don't understand why write permission isn't required to be declared when you use /fopen.


Beware of MeStinkBAD! He knows more than he actually does!
Re: Get mIRC to watch text file and dump text live [Re: MeStinkBAD] #223257 19/07/10 09:59 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Don't you know anything about /filter at all? AT ALL? I find it SO frustrating people don't understand what is truly a basic concept.

Code:
alias filetest {
  if (%filetest.lastfpos !isnum) {
    set %filetest.lastfpos 1
  }
  var %file = $qt($1-), %lines = $lines($1-)
  if (%filetest.lastfpos == %lines) return
  filter -rfk $+(%filetest.lastfpos,-,%lines) %file _filetest
  set %filetest.lastfpos %lines
}
alias -l _filetest {
  if ($1-) echo -a $1-
}


Consistently performs twice as fast as the file handling method smile
Oh yeah, less code too.

Re: Get mIRC to watch text file and dump text live [Re: MeStinkBAD] #223259 19/07/10 10:15 PM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I never said or implied that there wasn't a better/faster way of accessing the file. The post that I was replying to used $read, thus that is what I referenced.

Re: Get mIRC to watch text file and dump text live [Re: hixxy] #223326 21/07/10 06:41 AM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline
Fjord artisan
Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
Originally Posted By: hixxy
Don't you know anything about /filter at all? AT ALL? I find it SO frustrating people don't understand what is truly a basic concept.

Code:
alias filetest {
  if (%filetest.lastfpos !isnum) {
    set %filetest.lastfpos 1
  }
  var %file = $qt($1-), %lines = $lines($1-)
  if (%filetest.lastfpos == %lines) return
  filter -rfk $+(%filetest.lastfpos,-,%lines) %file _filetest
  set %filetest.lastfpos %lines
}
alias -l _filetest {
  if ($1-) echo -a $1-
}


Consistently performs twice as fast as the file handling method smile
Oh yeah, less code too.


/fseek takes no time at all. Like 0 ms to move to any position in the file. Regardless of size. /filter has to read the entire file every time. And you use $lines which also reads the entire file.

What my alias does is read thru the file the first time, then stores the file pointer position at the current end of the file. Each subsequent time, it then attempts to read the file starting where the file ended the prior time. If the file hasn't changed, it reads nothing, and the file position stays the same. If the file has been appended with new data, it reads up to the new data and stores the new position of the file pointer.

The amount of code is irrelevant. And why did you change the subject? I shouldn't even be responding to this. But you've distorted what I stated. Hixxy, fseek is a low level operation. One that mIRC itself performs. The /fseek command basically

Last edited by MeStinkBAD; 21/07/10 07:32 AM.

Beware of MeStinkBAD! He knows more than he actually does!
Re: Get mIRC to watch text file and dump text live [Re: MeStinkBAD] #223330 21/07/10 07:09 AM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
/filter doesn't read the entire file when the -r switch is specified, it reads the range specified with the [n-n2] parameter.

Like I said, this works twice as fast as the file handling alternative.

Re: Get mIRC to watch text file and dump text live [Re: hixxy] #223331 21/07/10 07:32 AM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline
Fjord artisan
Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
Originally Posted By: hixxy
/filter doesn't read the entire file when the -r switch is specified, it reads the range specified with the [n-n2] parameter.


Just stop it Hixxy. This thread isn't about /filter versus file handles. I've explained how alias works. And that's all I can do. Stop stating one is faster than the other. It's nowhere near as simple as that.

Last edited by MeStinkBAD; 21/07/10 07:44 AM.

Beware of MeStinkBAD! He knows more than he actually does!
Re: Get mIRC to watch text file and dump text live [Re: MeStinkBAD] #223335 21/07/10 10:06 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Remember that YOU are the one who started the "this is better than that" argument. If you can't accept someone else has a better/faster method, then don't start such discussions.


Invision Support
#Invision on irc.irchighway.net
Re: Get mIRC to watch text file and dump text live [Re: hixxy] #223337 21/07/10 10:35 AM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
hixxy :*

we could also use /loadbuf -a here :P


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Re: Get mIRC to watch text file and dump text live [Re: Riamus2] #223343 21/07/10 01:00 PM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline
Fjord artisan
Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
Originally Posted By: Riamus2
Remember that YOU are the one who started the "this is better than that" argument. If you can't accept someone else has a better/faster method, then don't start such discussions.


I didn't start this. I offered a solution. A solution that works and can used even inside a hires timer monitoring a very large file and have no impact on mIRC's performance. It won't lockup. And if you don't believe me try using it yourself.

You know... just go here... http://en.wikipedia.org/wiki/Fseek

It's because of people like hixxy that make trying to explain how to use file handles next to impossible, F*ck it I think it's most of you people who have post counts into the 1000s. Really. I do.

Last edited by MeStinkBAD; 21/07/10 01:17 PM.

Beware of MeStinkBAD! He knows more than he actually does!
Page 1 of 2 1 2