Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? Run a command (alias, actually) on a "timed" basis...

May
855
0
I mentioned in a previous thread that I lost my "history" when TCC sessions ended unexpectedly or I had to terminate them for some reason and that this was a problem for me. So I solved a major part of the problem by creating an alias:
Code:
Alias SA=`History >!"Z:TCC Histories\%@If[%_Elevated == 1,Elevated]PID%_PID.txt`
which has been thoroughly tested (not that was that was very hard) and works just like I would like. But I don't trust that I'll remember to actually use it on a regular basis (given my oft-mentioned levels of general incompetency) and therefore would like it automatically run it on a "scheduled" basis. It strikes me that putting it in a batch file with a "Delay", for example, doesn't do it because the TCC session will be essentially unusable while said batch file is executing. So is there any way to accomplish this goal? (I kind of suspect that there is not, but given the powers and scope of TCC, I could very well be wrong.)

- Dan
 
I don't know about doing it on a timed basis, but it would be pretty trivial to create a PRE_EXEC alias which dumps your history after every n commands.
 
Thank you, Charles, that was almost exactly on target (the "almost" because "POST_EXEC" works even better for my needs). I don't feel too bad about not knowing about it because it was evidently introduced in version 12. - Dan
 
Dan,

I was going to suggest a similar approach as Charles' suggestion. The help topic on ALIAS has a description for three special aliases:

The PRE_INPUT, PRE_EXEC, and POST_EXEC Aliases

When at the command prompt (i.e., not executing a batch file), TCC will look for (and execute them if found) the following aliases:

PRE_INPUT - executed immediately before accepting input for a new command line.

PRE_EXEC - executed immediately after a command line is entered (before any expansion or redirection).

POST_EXEC - executed immediately after returning from a command and before displaying the prompt.

None of these aliases will be passed any arguments.

If the alias does not exist, TCC will search the plugins for PRE_INPUT / PRE_EXEC / POST_EXEC functions and execute them if found.

Perhaps something like:
Code:
alias PRE_EXEC=`echo %_cmdline >>!"Z:TCC Histories\%@If[%_Elevated == 1,Elevated]PID%_PID.txt`

That will copy *every* command you type into the history PID text file.

-Scott
 
I have something like this in my tcstart.btm:
Code:
set     docpath=%@regquery["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\personal"]
if      not defined docpath set docpath=%userprofile
log     /h /w "%docpath\4nt.log"
 
...
 
(system)  C:\...\TCCLE13x64 >echo %_hlogfile
C:\Users\Frank\Documents\4nt.log
So at least I have a protocol of the issued commands, because tomorrow I can't remember what I did today ;-)
And if I have to search for a command I used someday, I have an alias
Code:
alias fh=history|findstr /i "%$"
eventually
Code:
alias fl*og=findstr /i "%$" "%_hlogfile"
I know this is not exactly what was asked, but perhaps it helps, too.
 
Scott, thank you, that's also a very good idea. However, I decided (somewhat arbitrarily, I suppose) to only do the "history" every 20th command. So the implementation of such used a very-simple alias:
Code:
POST_EXEC=SaveHistory.btm
And "SaveHistory.btm" is simple and straightforward other than the fact that I'm somewhat obsessed with error detection and (if possible) correction.
Code:
@Echo Off
If "CurrentCommandCount" == "" ^
  Set CurrentCommandCount=0
Set /A CurrentCommandCount+=1
If %CurrentCommandCount GE 0 .AND. %CurrentCommandCount LT 20 ^
  Quit 0
If NOT EXIST "Z:\TCC Histories" ^
  If EXIST Z: ^
      MD "Z:\TCC Histories" >NUL:
Iff NOT IsDir "Z:\TCC Histories" Then
  Iff %CurrentCommandCount GE 0 Then
      @Echo >CON: Warning: A directory named "Z:\TCC Histories" either does not exist or
      @Echo >CON:          is not a directory.
      Set CurrentCommandCount=-999
  EndIff
  Quit 0
EndIff
Iff NOT EXIST "Z:\TCC Histories\SaveHistory.btm" Then
  Copy D:\DOS\SaveHistory.btm "Z:\TCC Histories" >NUL:
  Attrib +R "Z:\TCC Histories\SaveHistory.btm"  >NUL:
EndIff
History >!"Z:TCC Histories\%@If[%_Elevated == 1,Elevated]PID%_PID.txt
Set CurrentCommandCount=0
Quit 0
Note that, as I have mentioned many times before, my "Z:" drive is a RAM disk so the performance impact of doing the above probably would (and so far seems to be – I’ve been using it for well more than an hour) essentially non-existent. And the RAM disk software saves its contents (as a whole) to a file on a physical hard disk on system shutdown and reloads itself from the same file on system start up as well as saving its contents to that same file at user-selected time intervals so that I'm not really worried about “losing” the .btm file. Also, I don’t think that you will find it really surprising that I have the same .btm file in a directory on a physical hard disk that is in my path (as the "TCC Histories" directory is in my path) so that it is guaranteed to "exist" (although while there might be a performance impact from using it from there on a long-term basis that really shouldn't happen) but that doesn’t really matter because if my RAM disk is empty or doesn’t even exist for some strange reason things will still run normally. (And if the .btm file can't find/create ""Z:\TCC Histories"" it produces a harmless error message exactly once but otherwise things proceed normally.) At some point in the future I may do it for every command as it is issued as you suggest, but I tend to doubt that I will because I like the error detection and correction that the existing batch file does.

And I do have to remember to "clean out" the "TCC Histories" directory once in a while...
 
And a quick note to you other guys who did postings while I was writing and testing my .btm file: I haven't had a chance to examine your postings yet in any detail (and I will) but thank you. And Frank, I had no idea TCC had a "log" command - I've been using this product for about 20 years and it still has things that surprise me. But I think I like the history approach a little bit more because I have "history" set so that when I use the same command multiple (or many!) times it only shows up once (HistDups=Last) in the output of the "history" command and the commands are ordered first used to last used (HistMove=Yes) in the history list. And I can also read this history (History /R) in a later session and I tend to doubt if you can do that quite as easily with the log file. - Dan
 
Hi Dan,
Your RAM Disk software sounds great! What is it?
(I'm actually now looking for some good RAM Disk software...)

Scott, thank you, that's also a very good idea. However, I decided (somewhat arbitrarily, I suppose) to only do the "history" every 20th command. So the implementation of such used a very-simple alias:
Code:
POST_EXEC=SaveHistory.btm
And "SaveHistory.btm" is simple and straightforward other than the fact that I'm somewhat obsessed with error detection and (if possible) correction.
Code:
@Echo Off
If "CurrentCommandCount" == "" ^
  Set CurrentCommandCount=0
Set /A CurrentCommandCount+=1
If %CurrentCommandCount GE 0 .AND. %CurrentCommandCount LT 20 ^
  Quit 0
If NOT EXIST "Z:\TCC Histories" ^
  If EXIST Z: ^
      MD "Z:TCC Histories" >NUL:
Iff NOT IsDir "Z:\TCC Histories" Then
  Iff %CurrentCommandCount GE 0 Then
      @Echo >CON: Warning: A directory named "Z:\TCC Histories" either does not exist or
      @Echo >CON:          is not a directory.
      Set CurrentCommandCount=-999
  EndIff
  Quit 0
EndIff
Iff NOT EXIST "Z:TCC Histories\SaveHistory.btm" Then
  Copy D:\DOS\SaveHistory.btm "Z:\TCC Histories" >NUL:
  Attrib +R "Z:\TCC Histories\SaveHistory.btm"  >NUL:
EndIff
History >!"Z:TCC Histories\%@If[%_Elevated == 1,Elevated]PID%_PID.txt
Set CurrentCommandCount=0
Quit 0
Note that, as I have mentioned many times before, my "Z:" drive is a RAM disk so the performance impact of doing the above probably would (and so far seems to be – I’ve been using it for well more than an hour) essentially non-existant. And the RAM disk software saves its contents (as a whole) to a file on a physical hard disk on system shutdown and reloads itself from the same file on system start up as well as saving its contents to that same file at user-selected time intervals so that I'm not really worried about “losing” the .btm file. Also, I don’t think that you will find it really surprising that I have the same .btm file in a directory on a physical hard disk that is in my path (as the "TCC Histories" directory is in my path) so that it is guaranteed to "exist" (although while there might be a performance impact from using it from there on a long-term basis that really shouldn't happen) but that doesn’t really matter because if my RAM disk is empty or doesn’t even exist for some strange reason things will still run normally. (And if the alias can’t “find” the .btm file it produces a harmless error message exactly once but otherwise things proceed normally.) At some point in the future I may do it for every command as it is issued as you suggest, but I tend to doubt that I will because I like the error detection and correction that the existing batch file does.

And I do have to remember to "clean out" the "TCC Histories" directory once in a while...
 
It took a few minutes to find out because of my bad memory as usual, Avi, but I was finally able to "dig it up". You can get it from http://memory.dataram.com/products-and-services/software/ramdisk, and it is free for "disks" less than or equal to 4GB in size (mine is 402,632,704 bytes and I'm not even sure I could get much larger given that this machine is using a 32-bit processor and I have just under 4GB of actual, physical, RAM) and $17.99 for sizes greater than that (I would assume 64-bit Windows but I don't know that). Said software has only two disadvantages that I can see: writing itself to a physical hard disk on shutdown and reloading itself from same on system start up could take a while if you have rather slow physical hard disks and/or a very large RAM disk, and you lose everything done on the RAM disk since the last write to the file on the physical hard disk if Windows crashes, but I've configured it to automatically save itself to a physical hard disk every 30 minutes so I would lose, at most, half an hour's work and Windows 7 has been very stable for me. I would guess that saving and reloading itself from a physical hard disk takes 2 to 3 minutes or so on this machine, but it's definitely worth it for me. And it's got a nice configuration utility where you specify its size and how often it saves itself to a physical hard disk (mine is set for every 30 minutes at the moment) and where that file is (i.e., what physical drive letter and directory). And as I remember, if you don't initially select "Unformatted" it comes up as some kind of FAT drive which I didn't want, but when you do (which I did) you can then format it NTFS just like any other drive. The version I am using now automatically assigns it to the next available drive letter whereas a previous version let you configure that (and I had configured it to drive Z: ), so that my RAM disk is really drive J: on this machine but I have Z: subst'd to drive J: on system startup. (Having it change from Z: to J: would have been somewhat of a problem because I've got a number of things that I've written where Z: is hard-coded because I specifically don't want them to run on a real, physical, hard disk and doing that made that impossible so I couldn't make a stupid mistake as I am so fond of doing.) And I have timed it: it is more than 3,000 times faster than the physical hard disk in this machine. For me it's wonderful.
 
And Frank, I had no idea TCC had a "log" command - I've been using this product for about 20 years and it still has things that surprise me. - Dan
Hello Dan,

this is a real story:
Many years ago I installed a game called "Logical". It was a nice game where you had to operate the appropriate switches at the right moment to get colorful spheres bumping from above into the right order to solve a level.
The comprehensive "installation guide" (a small one-sided paper) said: after installation goto the game's directory and type "log".
So what do you think what happened?

Code:
c:\games\logical> log
log is off
c:\games\logical>
I was totally perplex about that and it took me quite a while to figure out what has happend ;)
Since then I know there is a log command in 4dos (or was it 4nt already?) :D .

kind regards
Frank
 
Hi Dan,
Thanks for the info!
- Avi

It took a few minutes to find out because of my bad memory as usual, Avi, but I was finally able to "dig it up". You can get it from http://memory.dataram.com/products-and-services/software/ramdisk, and it is free for "disks" less than or equal to 4GB in size (mine is 402,632,704 bytes and I'm not even sure I could get much larger given that this machine is using a 32-bit processor and I have just under 4GB of actual, physical, RAM) and $17.99 for sizes greater than that (I would assume 64-bit Windows but I don't know that). Said software has only two disadvantages that I can see: writing itself to a physical hard disk on shutdown and reloading itself from same on system start up could take a while if you have rather slow physical hard disks and/or a very large RAM disk, and you lose everything done on the RAM disk since the last write to the file on the physical hard disk if Windows crashes, but I've configured it to automatically save itself to a physical hard disk every 30 minutes so I would lose, at most, half an hour's work and Windows 7 has been very stable for me. I would guess that saving and reloading itself from a physical hard disk takes 2 to 3 minutes or so on this machine, but it's definitely worth it for me. And it's got a nice configuration utility where you specify its size and how often it saves itself to a physical hard disk (mine is set for every 30 minutes at the moment) and where that file is (i.e., what physical drive letter and directory). And as I remember, if you don't initially select "Unformatted" it comes up as some kind of FAT drive which I didn't want, but when you do (which I did) you can then format it NTFS just like any other drive. The version I am using now automatically assigns it to the next available drive letter whereas a previous version let you configure that (and I had configured it to drive Z: ), so that my RAM disk is really drive J: on this machine but I have Z: subst'd to drive J: on system startup. (Having it change from Z: to J: would have been somewhat of a problem because I've got a number of things that I've written where Z: is hard-coded because I specifically don't want them to run on a real, physical, hard disk and doing that made that impossible so I couldn't make a stupid mistake as I am so fond of doing.) And I have timed it: it is more than 3,000 times faster than the physical hard disk in this machine. For me it's wonderful.
 

Similar threads

Back
Top