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

May 24, 2010
855
0
Northlake, Il
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
 
May 24, 2010
855
0
Northlake, Il
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
 

samintz

Scott Mintz
May 20, 2008
1,503
16
Solon, OH, USA
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
 
Aug 2, 2011
258
4
Berlin, Germany
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.
 
May 24, 2010
855
0
Northlake, Il
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...
 
May 24, 2010
855
0
Northlake, Il
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
 
Feb 23, 2012
240
3
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...
 
May 24, 2010
855
0
Northlake, Il
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.
 
Aug 2, 2011
258
4
Berlin, Germany
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
 
Feb 23, 2012
240
3
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
Thread starter Title Forum Replies Date
Jay Sage Command Will Not Run Using Short Name of Path Support 5
P Run as Admin tab in non-elevated Take Command session? Support 9
C How to? run a batch file in administrator mode while debugging in take command software Support 1
tmaynard How to? Any way to run a command in a new tab at startup? Support 18
M Installed but can't run Take Command 16.0 Support 5
B Select and run lines from Command Input panel? Support 1
A How to? Run a TCC command from external program Support 2
vefatica What limit have I run into? Support 9
S How to? Runs start /w in invisible mode OR run program after exit of another one Support 3
Peter Murschall BDEBUGGER "Run to Cursor" - where is it ? Support 1
Jay Sage Problem with Context Menu Copy+Paste+Run Key Assignment Support 7
D What does the file "..\Everything\Run history.csv" store? Support 5
dcantor How to? Can 32-bit TCC be run on a system with 64-bit TCMD and TCC installed? Support 6
G tcedit ist not run in tc 24 file explorer Support 10
A Windows 10 This app can't run on your PC Support 2
Roedy run as administrator Support 27
rps Documentation "Copy+Paste+run" question Support 2
Peter Murschall IDE/BDEBUUGER in TCC 22 didn't run Support 7
fpefpe How to? which will run? Support 1
C How to? run a BTM in elevated, inv tcc tab window Support 9
M How to? Run the control panel from a TCC session... Support 2
M How to? Run TCC from Windows Install DVD... Support 2
B Batch file won't run if there is already an instance of TC 17 running Support 9
P MS VS2013 vsdevcmd.bat fails to run with tcmd 17 x64 Support 10
redwdc btm won't run in ver. 17 but works in ver. 16 Support 11
Joe Caverly How to? Run DOS .exe's the same way Wine does... Support 3
vefatica Why isn't TCSTART.BTM run? Support 8
D Run all .CMD batch files with CMD.EXE Support 16
Joe Caverly Run As Administrator in TCMD16 Support 3
F Sending "Y" to chkdsk to run on C at next reboot Support 25
T tcc /c "[...]" fails when run from third party terminal Support 11
Jay Sage Specified INI File Refuses to Run Support 3
C How to? create a JPSoft BTM menu to run custom custom batch files Support 2
vefatica Coruption after which BTMs won't run Support 7
Joe Caverly Copy Paste Run Support 12
S Fixed TCC.EXE 13.03.47 won't run Support 4
Stefano Piccardi run as limited user Support 2
M How to? Windows 7 - run TCC as admin w/o UAC intercept Support 4
E TCC requires elevation to run Support 2
Jay Sage How to Run Non-Elevated From Elevated TCC Support 1
L How can I run tcmd in terminal window only? Support 13
S Run as Administrator question Support 3
Joe Caverly TCMD12 Beta Expired, TCMD11 will not run Support 7
p.f.moore Run as administrator from TCC Support 2
vefatica Help from IDE fails after a non-debug run Support 5
B TCC doesn't run using another user Support 2
A How to Run the 4NT 8.02 .INI Key Version Support 3
K double click to run btm? Support 2
D TCC won't run telnet on Windows 7 RC1 Support 5
D Can I use TC to run Cygwin? Support 4

Similar threads