TPIPE problem

May 20, 2008
11,400
99
Syracuse, NY, USA
With this line in my otherwise empty TCEXIT.BTM (or TCSTART.BTM)
Code:
SET /U /A TCCCount+=1
the command below shows its output immediately but the prompt doesn't return for about 40 seconds. If, during that time I try to interrupt with Ctrl-C, TPIPE.EXE crashes and after I say "Close the program, I get a message box:
Code:
Error
Runtime error 217 at 00011D18
OK
and the TCC instance is crippled thereafter.
 
May 20, 2008
11,400
99
Syracuse, NY, USA
Much more simply, and probably related, with the one line "SET /U /A TCCCount+=1" in TCEXIT, there is a 5 second delay after clicking the console's "X" and before TCC terminates. If I remove "/U" all's OK. Can't access the registry during TCEXIT?
 
May 20, 2008
11,400
99
Syracuse, NY, USA
You never showed the "command".
Oops! It was this.
Code:
v:\> type "http://forecast.weather.gov/MapClick.php?CityName=Syracuse&state=NY&site=BGM&textField1=43.0446&textField2=-76.1459&e=0" | tpipe /grep=3,0,0,1,0,0,0,0,"point-fore.*High|point-fore.*Low" /simple=16 /selection=7,0,2,2,0,5,"&",0 /simple=19 /replace=0,1,0,1,0,0,0,0,0,"Low: ","Low:  "
High: 22
Low:  17
High: 36
Low:  35
High: 47
Low:  42
High: 55
Low:  31
High: 35
 
May 20, 2008
11,400
99
Syracuse, NY, USA
Much more simply, and probably related, with the one line "SET /U /A TCCCount+=1" in TCEXIT, there is a 5 second delay after clicking the console's "X" and before TCC terminates. If I remove "/U" all's OK. Can't access the registry during TCEXIT?
And the variable is not incremented. And this remains so if I load no plugins (/IP).
 
May 20, 2008
11,400
99
Syracuse, NY, USA
Much more simply, and probably related, with the one line "SET /U /A TCCCount+=1" in TCEXIT, there is a 5 second delay after clicking the console's "X" and before TCC terminates.
My guess would be that TCC itself does not respond to the WM_SETTINGSCHANGE message which it (itself) generated as a result of "SET /U". Is it good old-fashioned deadlock? I'd guess there's a way around it since EXIT works OK (when clicking the "X" doesn't).
 

samintz

Scott Mintz
May 20, 2008
1,503
16
Solon, OH, USA
Not that it should matter, but have you tried the TCC syntax instead of the CMD syntax?
Code:
set /u TCCCount=%@inc[TCCCount]
echo %@regset[HKCU\Environment\TCCCount,REG_DWORD,%@inc[TCCCount]]
echo %@regsetenv[HKCU\Environment\TCCCount,REG_DWORD,%@inc[TCCCount]]
-Scott
 
May 20, 2008
11,400
99
Syracuse, NY, USA
Not that it should matter, but have you tried the TCC syntax instead of the CMD syntax?
Code:
set /u TCCCount=%@inc[TCCCount]
echo %@regset[HKCU\Environment\TCCCount,REG_DWORD,%@inc[TCCCount]]
echo %@regsetenv[HKCU\Environment\TCCCount,REG_DWORD,%@inc[TCCCount]]
-Scott
Yes. The first of those above misbehaves as I have described. The second is the one I'm using; it works OK.
 
May 20, 2008
11,400
99
Syracuse, NY, USA
Code:
set /u TCCCount=%@inc[TCCCount]
echo %@regset[HKCU\Environment\TCCCount,REG_DWORD,%@inc[TCCCount]]
echo %@regsetenv[HKCU\Environment\TCCCount,REG_DWORD,%@inc[TCCCount]]
Yes. The first of those above misbehaves as I have described. The second is the one I'm using; it works OK.
And the third of those above works OK.
There's something amiss. Of @REGSETENV, the help says "The same as @REGSET, but a broadcast message is sent to all applications when the change is made". But checking with a new CMD started by Explorer suggests no message was sent; a new CMD does not get an updated environment after TCC has
Code:
ECHO %@REGSETENV[HKCU\Environment\TCCCount,REG_SZ,%@INC[%@REGQUERY[HKCU\Environment\TCCCount]]]

On the other hand, the help for "SET /U" makes no mention of broadcasting a message but a message is broadcast. New CMDs started by Explorer do get an updated environment after TCC has
Code:
SET /U TCCCount=%@INC[%TCCCount]
 

rconn

Administrator
Staff member
May 14, 2008
12,344
149
Much more simply, and probably related, with the one line "SET /U /A TCCCount+=1" in TCEXIT, there is a 5 second delay after clicking the console's "X" and before TCC terminates. If I remove "/U" all's OK. Can't access the registry during TCEXIT?


This is a complicated scenario with no simple solution -- and what's happening is probably not what you think is happening.

When you click on the "X", the system sends a WM_ENDSESSION to the message handling window that TCC creates for itself (otherwise, like other console apps, TCC would not be able to intercept or respond to those messages). Upon receipt of the WM_ENDSESSION, TCC calls the EXIT command. Your TCEXIT.BTM is opened, and the "SET /U ..." line is executed. That eventually triggers an HWND_BROADCAST / WM_SETTINGCHANGE message, which is required to use the SendMessageTimeout API. (It cannot use something like PostMessage because it has to pass a pointer in LPARAM.) The SendMessageTimeout API is passed a 5-second timeout, and it starts calling all of the top level windows.

Eventually, the TCC window is called -- but it cannot process the message, because it's still in the WM_ENDSESSION message. (If TCC did something like a ReplyMessage() in the WM_ENDSESSION call, TCC would terminate immediately without being able to run TCEXIT.) So Windows waits 5 seconds, decides that TCC isn't going to process the WM_SETTINGCHANGE message, and continues notifying the other top-level windows. At roughly the same time, Windows also decides that TCC isn't going to return from the WM_ENDSESSION, so Windows summarily terminates TCC.

So -- the moral of the story is don't do things in your TCEXIT that require nested message handling in the console window. (Or stop clicking on "X" to close TCC!)

Alternatively, I could reduce the timeout for SendMessageTimeout to something less (one second?), though I suspect you'd then file a bug that TCC takes a second to exit after clicking "X" with a SET /U in TCEXIT. :dead:
 
May 20, 2008
11,400
99
Syracuse, NY, USA
That's what I figured (in principle, anyway); thanks for the details. I can live with that.

But there remains the fact that that @REGSETENV[HKCU\Environment\...] either doesn't broadcast any message or broadcasts one which fails to make Explorer (just for example) update its environment (as Explorer does when I "SET /U").

This is a complicated scenario with no simple solution -- and what's happening is probably not what you think is happening.

When you click on the "X", the system sends a WM_ENDSESSION to the message handling window that TCC creates for itself (otherwise, like other console apps, TCC would not be able to intercept or respond to those messages). Upon receipt of the WM_ENDSESSION, TCC calls the EXIT command. Your TCEXIT.BTM is opened, and the "SET /U ..." line is executed. That eventually triggers an HWND_BROADCAST / WM_SETTINGCHANGE message, which is required to use the SendMessageTimeout API. (It cannot use something like PostMessage because it has to pass a pointer in LPARAM.) The SendMessageTimeout API is passed a 5-second timeout, and it starts calling all of the top level windows.

Eventually, the TCC window is called -- but it cannot process the message, because it's still in the WM_ENDSESSION message. (If TCC did something like a ReplyMessage() in the WM_ENDSESSION call, TCC would terminate immediately without being able to run TCEXIT.) So Windows waits 5 seconds, decides that TCC isn't going to process the WM_SETTINGCHANGE message, and continues notifying the other top-level windows. At roughly the same time, Windows also decides that TCC isn't going to return from the WM_ENDSESSION, so Windows summarily terminates TCC.

So -- the moral of the story is don't do things in your TCEXIT that require nested message handling in the console window. (Or stop clicking on "X" to close TCC!)

Alternatively, I could reduce the timeout for SendMessageTimeout to something less (one second?), though I suspect you'd then file a bug that TCC takes a second to exit after clicking "X" with a SET /U in TCEXIT. :dead:
 
Similar threads
Thread starter Title Forum Replies Date
David McClelland TPIPE matching problem Support 3
samintz How to? TPIPE /simple=61 Support 6
R Bug TPIPE's pdf to text conversions don't work Support 2
Kachupp How to? tpipe Support 4
H TPIPE /simple=4 Support 12
D TPIPE produces unwanted logs. Support 1
Kachupp How to? tpipe Support 8
vefatica Documentation TPIPE, /perl, DotMatchesNewLines Support 1
vefatica Stop TPIPE /EOL removing bad EOLs (and TPIPE changine EOLs)? Support 2
vefatica TPIPE in an alias? Support 2
C How to? TPIPE ?'s Support 2
H History and TPipe Oddness Support 3
Jay Sage Baffling Behavior With TPIPE Support 5
vefatica TPIPE: unbalanced escaped quotes in a regex? Support 5
Joe Caverly Multiple Text Searches at once using FFIND or TPIPE Support 4
Kachupp FFIND TPIPE Support 9
vefatica TPIPE and avarice? Support 5
Peter Murschall TPIPE generate unicode on Piping or redirecting Support 3
x13 TPIPE /REPLACE - Remove line (including EOL) Support 3
Charles Dye Documentation TPIPE /REPLACELIST Support 0
Joe Caverly TPIPE and /inputstring Support 3
vefatica How to? Add real <ESC> characters with TPIPE Support 2
vefatica How to? TPIPE ... see output right away? Support 4
vefatica TPIPE.EXE crashes on Ctrl-C Support 9
O TPIPE: Error -Can´t access textpipeengine.dll Support 24
vefatica Extract fields with TPIPE? Support 10
vefatica TPIPE, crash and question Support 1
MickeyF Another TPIPE question Support 6
MickeyF Can't get my TPIPE /replace to work Support 4
Joe Caverly Printing TPIPE documentation Support 3
C WAD tpipe /simple=28 Support 8
vefatica Remove double-quotes with TPIPE Support 4
vefatica TPIPE crashes on Ctrl-C Support 1
C How to? Add date/time to custom tpipe based BTM Support 1
C tpipe /simple=28 error Support 5
C TPipe /dup Support 5
T TPipe: Replacing String with Double Quotes Support 3
C tpipe and extract email addresses Support 1
vefatica How do I do this with TPIPE? Support 1
vefatica TPIPE's /perl option? Support 1
D TPIPE help typo Support 0
vefatica TPIPE access violations are back Support 2
Joe Caverly Word Count using TPIPE Support 10
Dan Glynhampton TPIPE in Build 41 Support 4
Phileosophos TPIPE doesn't work at all with v16 Support 3
vefatica TPIPE access violation again Support 1
vefatica TPIPE: Access violation Support 5
jbanaszczyk TCMD 16 - TPIPE Support 4
P TPipe relaunches TCC window and 4start, etc Support 7
Phileosophos Documentation TPIPE /string type code confusion Support 4

Similar threads