findstr fails under certain circumstances

MLK

Sep 24, 2008
3
0
The following line fails when run in tcc/le but not when run in cmd.exe (it is part of a batch file)

for /F %%v in ('echo %1^|findstr "^start$ ^stop$ ^restart$ ^install$ ^remove$ ^query$ ^ping$ ^setup"') do call :exec set COMMAND=%%v

The errors I get is:
FINDSTR: Cannot open ping$
FINDSTR: Cannot open etup >! C:\DOCUME~1\mortenk\LOCALS~1\Temp\FOR252.tmp


If I remove two of the "targets" (e.g. ^remove$ and ^query$) findstr works as intended.


Thanks for a great product
Morten
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,448
88
Albuquerque, NM
prospero.unm.edu
I haven't tried it, but I suspect that what you're seeing is not a FINDSTR problem per se, but differences in how the escape character is used. You might try disabling escape char processing via SETDOS /X-8 before the problematic line (and re-enabling it with SETDOS /X0 afterwards), or perhaps using SETDOS /E to change the escape character to something more obscure.
 

MLK

Sep 24, 2008
3
0
Thanks for the quick reply

I have tried SETDOS /X-8 and that results in the error message not being displayed.

When doing this the script however stops working.

Hope we can fix this somehow since I would like to be cmd-independent :)
 

rconn

Administrator
Staff member
May 14, 2008
12,340
149
MLK wrote:

> The following line fails when run in tcc/le but not when run in cmd.exe
> (it is part of a batch file)
>
> for /F %%v in ('echo %1^|findstr "^start$ ^stop$ ^restart$ ^install$
> ^remove$ ^query$ ^ping$ ^setup"') do call :exec set COMMAND=%%v
>
> The errors I get is:
> FINDSTR: Cannot open ping$
> FINDSTR: Cannot open etup >! C:\DOCUME~1\mortenk\LOCALS~1\Temp\FOR252.tmp
>
> If I remove two of the "targets" (e.g. ^remove$ and ^query$) findstr
> works as intended.

That line by itself won't work in either CMD or TCC. (What is the %1
argument? What is the "exec" call? What is the "set" command doing in
the CALL statement? Why are you using the escape character (^) in front
of all of the commands?)

Can you post a minimal batch batch file that works in CMD but fails in TCC?

Rex Conn
JP Software
 
May 20, 2008
11,391
99
Syracuse, NY, USA
On Thu, 25 Sep 2008 07:18:36 -0500, "JP Software Forums" <neil@jpsoft.com>,rconn
<> wrote:


>Can you post a minimal batch batch file that works in CMD but fails in TCC?

I don't know it this addresses all the OP's concerns, but one thing is the same
at the TCC command line. Giving FINDSTR one additional string to look for
(^foo$) causes the command to fail:

v:\> for /F %v in ('echo start | findstr "^start$ ^stop$ ^restart$ ^install$
^remove$ ^query$"') echo %v
start

v:\> for /F %v in ('echo start | findstr "^start$ ^stop$ ^restart$ ^install$
^remove$ ^query$ ^foo$"') echo %v
FINDSTR: Cannot open ?oo$ >! e:\temp\FORD60.tmp

**NOTE**: In that error message a "female sign" precedes "oo$".

Either command line, appropriately modified for CMD works at the CMD command
line (note, echo is ON).

v:\> for /F %v in ('echo start ^| findstr "^start$ ^stop$
^restart$ ^install$ ^remove$ ^query$"') do echo %v

v:\> echo start
start

v:\> for /F %v in ('echo start ^| findstr "^start$ ^stop$
^restart$ ^install$ ^remove$ ^query$ ^foo$"') do echo %v

v:\> echo start
start
 
May 20, 2008
3,515
4
Elkridge, MD, USA
JP Software Forums" <neil@jpsoft.com>; "Charles Dye wrote:
|
**NOTE**: In that error message a "female sign"
| precedes "oo$".
|
| That 'female sign' is most likely the form-feed character, Ctrl-L --
| generated in TCC by ^F.

... which may be the reason _this_ particular string causes failure. Its
introductory character is considered to be an EscapeChar, and instead of the
two-character sequence "caret f" (^f) the FF character is passed to FINDSTR.

Using SETDOS /E or OPTION //EscapeChar= to change the escape character from
TCC default should cure the OP's problem.
--
Steve
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,448
88
Albuquerque, NM
prospero.unm.edu
"Charles Dye wrote:
|
|
| That 'female sign' is most likely the form-feed character, Ctrl-L --
| generated in TCC by ^F.

... which may be the reason _this_ particular string causes failure. Its
introductory character is considered to be an EscapeChar, and instead of the
two-character sequence "caret f" (^f) the FF character is passed to FINDSTR.

Well, that and its position. Note that the preceding escape sequence (from "^query$") is ^Q, the double quote -- prematurely closing the quoted string. If you were to rearrange the search terms so that ^query$ was earlier in the list, I'll bet you'd see more problems.
 
May 30, 2008
42
0
From: JP Software Forums
Sent: Thursday, September 25, 2008 10:46 AM
Subject: RE: [Support-t-493] Re: findstr fails under certain circumstances
[snip]

> Well, that and its position. Note that the preceding escape sequence
> (from "^query$") is ^Q, the double quote -- prematurely closing the
> quoted string. If you were to rearrange the search terms so that ^query$
> was earlier in the list, I'll bet you'd see more problems.

I must admit, I'm somewhat concerned by the facts that this is actually able
to expose an internal implementation detail of FOR, and that that detail
involves writing the output of the command to a temporary file. =/ These are
both somewhat disconcerting to me.

Jonathan Gilbert
 
May 20, 2008
3,515
4
Elkridge, MD, USA
JP Software Forums" <neil@jpsoft.com>; "logic wrote:
| From: JP Software Forums
| Sent: Thursday, September 25, 2008 10:46 AM
| Subject: RE: [Support-t-493] Re: findstr fails under certain
| circumstances [snip]
|
|
> Well, that and its position. Note that the preceding escape
| sequence
|| (from "^query$") is ^Q, the double quote -- prematurely closing the
|| quoted string. If you were to rearrange the search terms so that
|| ^query$ was earlier in the list, I'll bet you'd see more problems.
|
|
| I must admit, I'm somewhat concerned by the facts that this is
| actually able to expose an internal implementation detail of FOR, and
| that that detail involves writing the output of the command to a
| temporary file. =/ These are both somewhat disconcerting to me.

No, there is nothing related to FOR implementation here. The issue is that
in 4NT and TCC the caret ^ character is the default for the command-line
EscapeChar, which combines with the immediately subsequent command line
character into a possibly inappropriate (for FINDSTR, that is) special
character, e.g., ^f is converted into FF, ^q into ", etc. The issue actually
exposed is that using the caret ^ as the default EscapeChar may be
incompatible with FINDSTR syntax.

I don't think the FOR created a temporary file, either. Neither issue that
you considered "disconcerting" has the property you did not consider best.
--
Steve
 
May 30, 2008
42
0
From: JP Software Forums
Sent: Thursday, September 25, 2008 9:43 PM
Subject: RE: [Support-t-493] Re: findstr fails under certain circumstances

>
> No, there is nothing related to FOR implementation here. The issue is
> that in 4NT and TCC the caret ^ character is the default for the command-
> line EscapeChar, which combines with the immediately subsequent command
> line character into a possibly inappropriate (for FINDSTR, that is)
> special character, e.g., ^f is converted into FF, ^q into ", etc. The
> issue actually exposed is that using the caret ^ as the default
> EscapeChar may be incompatible with FINDSTR syntax.
>
> I don't think the FOR created a temporary file, either. Neither issue
> that you considered "disconcerting" has the property you did not consider
> best.

Uh, sorry?

This is the original error message posted by MLK:


> The errors I get is:
> FINDSTR: Cannot open ping$
> FINDSTR: Cannot open etup >! C:\DOCUME~1\mortenk\LOCALS~1\Temp\FOR252.tmp

Jonathan Gilbert
 

MLK

Sep 24, 2008
3
0
The original line I posted is from the Hyperic HQ 4.0 Beta "hq-agent.bat".
(Sorry for not posting the line I made work in cmd but not in tcc)


I have checked whether a file was created, which was not the case.


The line I used for testing was this one:

for /F %v in ('echo ping^|findstr "^start$ ^stop$ ^restart$ ^install$ ^remove$ ^query$ ^ping$ ^setup"') do echo %v

which works in both cmd and fails in tcc.



To test the "^q=double quotes" I then tried removing the ^query$ only and adding a few more targets and I get this (in TCC):

[C:\]for /F %v in ('echo ping^|findstr "^start$ ^stop$ ^restart$ ^install$ ^remove$ ^ping$ ^setup ^bla ^bla2"') do echo %v
ping




When isolating the findstr like this:
echo ping|findstr "^start$ ^stop$ ^restart$ ^install$ ^remove$ ^query$ ^ping$ ^setup"

which works in tcc and cmd.



So somehow when "findstr" is wrapped in the "for" it fails. Could it perhaps be the single and doublequotes wrapping findstr?

Morten
 
May 30, 2008
42
0
From: JP Software Forums [mailto:neil@jpsoft.com]
Sent: Saturday, September 27, 2008 2:40 AM
Subject: RE: [Support-t-493] Re: findstr fails under certain circumstances
[snip]

> I have checked whether a file was created, which was not the case.

If you don't believe that a file is created, try this:

[C:\WINDOWS\system32]for /F %i in ('dir *.txt') do echo %i
eula.txt
h323log.txt
MSOracle32Readme.txt
SQLSRDME.TXT
VFPODBC.TXT

[C:\WINDOWS\system32]cacls "%temp" /E /D Everyone
processed dir: C:\DOCUME~1\JONATH~1\LOCALS~1\Temp

[C:\WINDOWS\system32]for /F %i in ('dir *.txt) do echo %i
4NT: (Sys) Access is denied.
"C:\DOCUME~1\JONATH~1\LOCALS~1\Temp"

[C:\WINDOWS\system32]cacls "%temp" /E /R Everyone
processed dir: C:\DOCUME~1\JONATH~1\LOCALS~1\Temp

[C:\WINDOWS\system32]for /F %i in ('dir *.txt') do echo %i
eula.txt
h323log.txt
MSOracle32Readme.txt
SQLSRDME.TXT
VFPODBC.TXT

[C:\WINDOWS\system32]

The first CACLS line adds an ACE to the Temp directory denying everyone
access. The second CACLS line deletes that ACE, restoring the ACL to its
previous state. I think it's pretty clear that FOR /F *does* write a
temporary file. This in and of itself isn't a serious problem, though I
wouldn't do it that way myself, but the way in which it is done is what
disturbs me. 4NT is, as far as I can infer from the error message earlier in
this thread, just tacking ">!" + GetTempFileName() onto the end of the
command-line within (' ') used when recursively invoking the command
processor to get the results. *That* is what disturbs me. =/

Jonathan Gilbert
 
Similar threads
Thread starter Title Forum Replies Date
I findstr works in cmd but not in tcc Support 5
samintz COPY fails to copy from \\wsl$ Support 20
M Goto fails when a text endtext block precedes the code Support 5
vefatica SETP usually fails with a 32 bit process Support 4
S INPUT fails if the entered text contains pair of square brackets Support 6
B Request Manual Key fails Support 3
L TCC V22 installer fails signature validation Support 0
A Fixed v25 regression: Parameter expansion fails in piped commands Support 2
vefatica START /PGM "name with spaces.URL" fails Support 2
I zip /M fails to delete file after adding to zip file Support 2
D skip= in FOR /F fails Support 9
Joe Caverly Using a Directory Alias with @iniwrite fails Support 14
A WAD Output redirection to IF block fails with "unbalanced brackets" Support 7
E My echo full file name to the clipboard fails now. Support 2
A Fixed (CMD compat) START /D fails to recognize the switch option. Support 3
B MKLINK requires admin - fails silently. Support 1
D Fixed Take Command 21.0.29 fails – MSVCP140.dll missed Support 6
F Powershell call fails with "Scripting Integrator 2016 (PowerShell)" license error Support 9
fishman@panix.com Version 21.23 fails to install Support 4
D unzip fails to find valid license Support 3
StarliteLemming Fileread fails on Unicode file Support 10
D Upgrade from 19 to 19.10 fails Support 2
C Upgrade to v19.10.42 fails Support 5
D V19 fails to install on Win7-64bit, installer says: Support 2
bervin Webform fails on HTTPS Support 1
thedave Windows 10: Pinned taskbar fails Support 20
P MS VS2013 vsdevcmd.bat fails to run with tcmd 17 x64 Support 10
vefatica @REGQUERY with hostname fails Support 12
tmaynard Bug Typesafe Activator fails under Take Command shell Support 2
R Fixed Internal ZIP command fails to process multiple files Support 3
P Copying descript.ion file fails Support 8
S WAD FTP copy fails in 16.00.25 Support 24
S WAD KEYSTACK fails in TCC-64 Support 2
vefatica Files disappear in Explorer when DEL fails Support 6
T tcc /c "[...]" fails when run from third party terminal Support 11
C Latest TCMDx64 fails on XP Pro x64 Support 1
dcantor WAD dir "ftp:// ..." fails in TCC 15 Support 7
M WAD Copy command fails rather weirdly... Support 2
S WAD COPY from FTP site fails in 14.03.51 Support 9
M Updating environment variable from C++ fails erratically in version 14... Support 57
dcantor Take Command 14 release fails Support 6
S WAD "Mark Forums Read" fails Support 4
dcantor Fixed Take Command 14.0.20 fails Support 19
D Upgrade from b12 fails Support 5
scottb Toolbar filter by directory attribute /A:D fails Support 1
Stefano Piccardi IDE.exe start toobar button fails when % in script path Support 0
H Install fails and removes tcmd Support 4
vefatica 12.10 registration fails Support 3
S PDIR fails in 12.10.55 Support 3
J 4console vbeep fails Support 0

Similar threads