Command history loosing entries

Jun 4, 2008
30
0
Hi.

Summary: When in TCC, invoking a perl program that invokes TCC will results in the command history buffer in the original TCC session being reloaded from the "user/TCC-Command-History.txt" file.

Convoluted, I know, but:

I have a perl program that invokes tcc via:
`tcc /I /L /Q /H /C start /elevated $batfile`
The program works, no problem there. Note the /L option which is supposed to use local command history (as well as other list).

Now I invoke tcmd (which has no local lists checked - ie uses global lists) and type in a couple of nonsense commands like:
asfdadf
xcvzzxcv
For each I get the expected 'unknown command' message. I then hit pgdown and see these command are in the command history as expected.
I then invoke the perl program. It runs and at this point I expect to have a command history looking like:
...previous commands from previous sessions...
asfdadf
xcvzzxcv
perlpgm.pl

Instead when I hit PgDown all I see is:
...previous commands from previous sessions...

I have lost the commands I have entered into this session of TCMD/TCC. In fact it appears that my command history has been reloaded from home/TCC-Command-History.txt as a result of running my perlpgm.pl

I had assumed that by invoking TCC with the /L option I would not effect my (global) command history in my current TCMD session.

Further testing shows that if I invoke the perl program via a start command my command history is as I expected - ie:
after invoking 'start perlpgm.pl' my command history is:
...previous commands from previous sessions...
asfdadf
xcvzzxcv
start perlpgm.pl

This appears to be a bug or at least not what I expected.

David
 
May 20, 2008
10,573
78
Syracuse, NY, USA
Hi, David.

TCMD has nothing to do with it.

What version of TCC do you use?

Where do you specify the name "TCC-Command-History.txt"? What causes it to be loaded? If that's done by your TCSTART.BTM then a common strategy (for avoiding various difficulties) is to use a first (or otherwise carefully placed) line like this in TCSTART.BTM.
Code:
if %_transient == 1 .or. %_pipe == 1 quit
In any event, if the original TCC has a global history and Perl starts one using "/L" that global history should not be discarded.
 
Jun 4, 2008
30
0
To answer your question:
1) TCC Options dialog->Command Line->History file=C:\Users\user-name\TCC-Command-History.txt
2) My TCMD/TCC window is started from the Windows start menu.
3) From that window/tab I invoke the perlpgm.pl which then invokes TCC with the /I option which is documented as
"Don't load the .INI file, execute TCSTART or TCEXIT, or load plugins. "
Therefore inserting the line you suggested in the TCSTART.BTM file would have no effect as it will not be executed.
4) It appears that the TCC-Command-History.txt doesn't get updated until TCMD terminates (Alt-F4)
5) and something in my invoking TCC via my program causes the original TCMD/TCC session to reload the history buffer from the history file thus causing me to lose my command history since I started TCMD/
6) Note that my TCMD/TCC session uses no local lists, just global ones.

BTW, thanks for you quick response.

David
 
Jun 4, 2008
30
0
You are right. I changed the bat file to add a pause and then used the SysInternals ProcExp to look at the command line of that window. It was "tcc.exe /K batfile.bat" as you said.

So what is triggering TCC #1 to reload the command history from the "user/TCC-Command-History.txt" file?

Note: I've tried a couple of things that had no effect:
1) Used a btm file instead of bat
2) Removed the /elevated flag from the start.
 
May 20, 2008
10,573
78
Syracuse, NY, USA
So what is triggering TCC #1 to reload the command history from the "user/TCC-Command-History.txt" file?
The history file you're using is loaded by every TCC at startup (and saved at exit as you noted earlier). Both TCC #1 and TCC #3 are using the same (global) history and TCC #3 loading that file is clobbering that history.

If you don't need "/elevated" then you don't need START (which starts TCC #3). Let TCC #2 run the batfile. Maybe (from Perl)
Code:
`tcc /i /l /q /h [/c] $batfile`
.

Or you could force TCC #3 to usev a local history, perhaps with something like this (untested)
Code:
`tcc /i /l /q /h /c start /elevated [path]\tcc /l [...] $batfile`
I don't think that history file and global history go well together. Hopefully others will chime in on what history mechanism they use and how they use it. I use a global history (also dirhistory, aliases, and functions). Read about SHRALIAS. It will guard global lists even when no TCCs are running; so the global history (and friends) is always there. SHRALIAS will automatically save the lists to files (in the %SHRALIAS_SAVE_PATH directory) when it exits, which it does automatically at logoff and shutdown. I load the saved lists in a logon script and start SHRALIAS (and never think about it again). I also have an OPTION\Startup\Logging\History\File set, but that's only to collect every command (I have ever issued) in case I later want to search for how I did something.
 
Jun 4, 2008
30
0
Oops. Ignore that last post.
I tried your suggestion:
1) Added %SHRALIAS_SAVE_PATH to my environment variables
2) Added "SHRALIAS" to my TCStart.btm
3) Stopped and restarted TCMD
4) Navigated to where my perlpgm.pl was
5) Checked to see that my navigation commands where in the command history buffer
6) Ran the Perl program
7) Checked the command history buffer

and it had been reset to what it was before I restarted TCMD

I then did a SHRALIAS /U and checked the history.sav file. It too did not have any of the directory navigation commands or the command to invoke my perl program.

Something in the chain of events initiated inside the perlpgm.pl is causing TCC#1 to reload it's command history from TCC-Command-History.txt upon completion of perlpgm.pl and it affect SHRALIAS as well.

And it is NOT the /elevated option. I removed that but the results were the same.

The bat or btm script runs two "reg" commands to export (not modify) a couple of registry components and a del command. I run elevated because of the permissions required for these registry entries.

I did try:
Win+R and entered: perl "C:\TestPad\InstalledApps\t_DecodeReg.pl"
The program ran and the command history in TCC#1 was not modified/reset. Looks like something to do with the parent-child chain of processes being run causing TCC#1 to reload the command history.

Puzzling.
 
May 20, 2008
10,573
78
Syracuse, NY, USA
Elevated or not, if you're using a history file any TCC using a global history, when it starts, is going to clobber the history of any currently-running TCC with a global history. As I said before, TCC #3 is doing that to TCC #1. My recommendation: don't use a history file.. Otherwise, figure out how to execute $batfile in a TCC with a local history.

Completely separate ... IMHO, SHRALIAS doesn't belong in TCSTART.BTM. It should be called only once in a login session (and IMHO, never stopped). Here, it goes like this:

1. I log on
2. My logon script is run by a TCC with a global history
3. The logon script does this (essentially)

Code:
iff defined SHRALIAS_SAVE_PATH then
    cdd %SHRALIAS_SAVE_PATH
    do c in /L history dirhistory alias function ( %c /r %c.sav )
endiff
shralias
Now I have global lists populated with the recently saved data. SHRALIAS (more precisely SHRALIAS.EXE, which is started by SHRALIAS) guards those lists so that they won't go away when there are no TCCs running. All TCCs with global lists will find/use those lists without doing anything at all. This continues indefinitely. I never stop SHRALIAS. Logging out, shutting down, or restarting causes SHRALIAS to save the lists.

If you're configured to have TCC run BTMs, you can put a login script (BTM) or shortcut to one, in "%USERPROFILE\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\StartUp".
 
May 20, 2008
10,573
78
Syracuse, NY, USA
Looks like something to do with the parent-child chain of processes being run causing TCC#1 to reload the command history.
TCC #1 isn't reloading the command history. TCC #1 is using a global history list and TCC #3 (using the same global history list) is loading the history file into that list.
 
Jun 4, 2008
30
0
So I simplified things. I wrote a test perl program called t_cmdhistory.pl containing one statement:
`c:\\testpad\\installedapps\\t_bat1.bat`;
The t_bat1.bat file is:
@echo This is t_btm1.btm
pause
exit

I checked my command history and then executed t_cmdhistory.pl

When I re-checked my command history it had been reloaded!

Note that t_cmdhistory.pl invokes cmd.exe to execute a batch file
 
May 20, 2008
10,573
78
Syracuse, NY, USA
I'm trying to duplicate your problem with a newly installed ActivePerl. I'm using this.
Code:
v:\> g:\perl\bin\perl test.pl
hello
v:\> type test.pl
print "hello";
`v:\\htest.bat`;

v:\> type htest.bat
echo This is HTEST.BAT.
ver
pause
CMD does start, and with the correct command line. But I don't see any output from the batfile. I see "Hello" from TEST.PL. But I don't see the batfile's ECHO'd message, the output of VER, or the pause prompt (though I must press a key, apparently to dismiss the pause). Have you any idea why I'm not seeing output from the batfile?

I'm using a history file and, so far, I have not seen the history overwritten in the (one and only) TCC from which I started TEST.PL.
 
May 20, 2008
10,573
78
Syracuse, NY, USA
I can get output if I use system(). It's not as you said using a BAT file (executed by CMD); my history is not affected.
Code:
v:\> option histfile
histfile=v:\bogus.txt

v:\> type bogus.txt
option histfile
history | tail /n 5
type v:\bogus.txt
bogus 1
bogus 2
bogus 3
exit

v:\> history | tail /n 5
bogus 3
exit
option histfile
type bogus.txt
history | tail /n 5

v:\> type test.pl
print "hello, this is test.pl\n";
system("v:\\htest.bat");

v:\> type htest.bat
@echo off
echo This is HTEST.BAT.
ver
pause

v:\> test.pl
hello, this is test.pl
This is HTEST.BAT.

Microsoft Windows [Version 6.1.7601]
Press any key to continue . . .

v:\> history | tail /n 8
exit
option histfile
type bogus.txt
history | tail /n 5
type test.pl
type htest.bat
test.pl
history | tail /n 8
 
Jun 4, 2008
30
0
I modified my test program (t_cmdhistory.pl) to select the method of call by the input argument: 1 = back tics, 2=system() and 3=back tics but executes a dos command, namely echo. Here is the program:

my $arg=shift//1;

if ($arg == 1) {
print "Using back-tics:\n";
`c:\\testpad\\installedapps\\t_bat1.bat`;
} elsif ($arg ==2) {
print "Using system()\n";
system("c:\\testpad\\installedapps\\t_bat1.bat");
} elsif ($arg == 3) {
print "Using back-tics and executing an echo command:\n";
`echo commmand invoke from perl`;
} else {
print "Oops - argument not understood";
}

I next execute this program three times with arguments 1, 2 ,3. Here is the screen printout:

[C:\TestPad\InstalledApps]t_cmdhistory.pl 1
Using back-tics:Press any key when ready...
[C:\TestPad\InstalledApps]t_cmdhistory.pl
Using back-tics:
Press any key when ready...
[C:\TestPad\InstalledApps]t_cmdhistory.pl 2
Using system()
This is t_bat.bat
pause
Press any key when ready...
exit

[C:\TestPad\InstalledApps]t_cmdhistory.pl 3
Using back-tics and executing an echo command:

[C:\TestPad\InstalledApps]history /t10
Installed\
..
InstalledApps\
t_cmdhistory.pl 1
t_cmdhistory.pl 3
history | tail /n 12
type t_cmdhistory.pl
=========================
t_cmdhistory.pl 3
history /t10

[C:\TestPad\InstalledApps]

In the "history /t10" output, ignore everything above ================ as these come before the current tests.

The first two runs (t_cmdhistory.pl 1 and then 2) are missing from the history file. Executing an echo command did not seem to affect the history file as "t_cmdhistory 3" is there in the listing.

A further note: during these tests I had my editor (Ultraedit) watching the history file. After tests 1 and 2 it indicated that the history file had been modified and asked if I wanted to reload the file. I selected 'yes' and both times the last line of the history file was ===============. This did not happen with test 3.

I am using Strawberry Perl 28.

Also in my windows startup sequence I run a btm file which in turn starts two perl processes and a btm script, all of which run continuously. I don't know if this is significant.
 
May 20, 2008
10,573
78
Syracuse, NY, USA
I'm no Perl expert and you have lost me. Earlier you said
So I simplified things. I wrote a test perl program called t_cmdhistory.pl containing one statement:
`c:\\testpad\\installedapps\\t_bat1.bat`;
When I do that (specify a batfile in backticks I don't see any output from the batfile. Should I?
 
May 20, 2008
10,573
78
Syracuse, NY, USA
As I said, you have lost me.

Simply,

1. A global history list will be changed when another TCC with global history starts (and appends the history file to the current global history).
2. The history file itself will change when a TCC exits.

1 above is a goodreason NOT to use a history file and a global history list. Every time you start another TCC, another copy of the history file is appended to the actual history. I emptied my global history and tried this little experiment.

Code:
v:\> @option histfile
histfile=v:\bogus.txt

v:\> history /r bogus.txt

v:\> history
history /r bogus.txt
line 1
line 2
line 3
history

v:\> do i=1 to 3 ( start /c /wait )

v:\> history
history /r bogus.txt
line 1
line 2
line 3
do i=1 to 3 ( start /c /wait )
line 1
line 2
line 3
history /r bogus.txt
line 1
line 2
line 3
do i=1 to 3 ( start /c /wait )
line 1
line 2
line 3
history /r bogus.txt
line 1
line 2
line 3
do i=1 to 3 ( start /c /wait )
line 1
line 2
line 3
history /r bogus.txt
line 1
line 2
line 3
do i=1 to 3 ( start /c /wait )
line 1
line 2
line 3
history
 
Jun 4, 2008
30
0
Ok. I guess we have spent enough time on this. I have changed my TCC options to use local lists. The reason I was using global ones is that I usually have two or more tabs running under tcmd and I wanted to share the command history between those tabs but I can live with local lists.

As for your perl question, back-ticks does not display the output from the command unless you put a print in front as in:
print `c:\\testpad\\installedapps\\t_bat1.bat`;
The system() call works differently as it does display the output automatically. Not that I knew this before this (long) conversation.

Thanks for all your help with this.

David
 
May 20, 2008
10,573
78
Syracuse, NY, USA
You're welcome.

I like global history (and SHRALIAS) because I want the list to be available from TCC to TCC ... from day to day ... from week to week.