Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

findstr

24 views
Skip to first unread message

Jean Pierre Daviau

unread,
Dec 2, 2009, 10:16:56 AM12/2/09
to
Hi to everyone,

I want to parse the input line to know wich :SUB is called.
Ex: n.cmd :LLL 1 2 3

If findstr returns :LLL, I can write call :%1 %2 %3 %4

---file--
set /p _a=%1
findstr /C:":" \< [%_a%]
----------

Jean Pierre Daviau

- - - -
Art: http://www.jeanpierredaviau.com
Maison � vendre:
http://www.jeanpierredaviau.com/maison/

foxidrive

unread,
Dec 2, 2009, 10:30:35 AM12/2/09
to
On Wed, 2 Dec 2009 10:16:56 -0500, "Jean Pierre Daviau" <on...@wasenough.ca>
wrote:

>Hi to everyone,
>
>I want to parse the input line to know wich :SUB is called.
>Ex: n.cmd :LLL 1 2 3
>
>If findstr returns :LLL, I can write call :%1 %2 %3 %4
>
>
>
>---file--
>set /p _a=%1
>findstr /C:":" \< [%_a%]
>----------


I don't understand what you are trying to do - is there a reason why you
can't use this, apart from the fact you will have doubled the full colon.

Jean Pierre Daviau

unread,
Dec 2, 2009, 10:41:19 AM12/2/09
to

> I don't understand what you are trying to do - is there a reason why you
> can't use this, apart from the fact you will have doubled the full colon.

No.
I dont know if this can be done

findstr ":" \< [%_a%]


> call :%1 %2 %3 %4

prompt>n.cmd :LLL 1 2 3
in the cmd file would be


......
call :LLL %2 %3 %4
:LLL
echo %2 %3 %4 would print 1 2 3
.....

Tom Lavedas

unread,
Dec 2, 2009, 11:06:02 AM12/2/09
to

You want to test for a valid subroutine name? In that case, try
something like this ...

@echo off
if "%1"=="" (echo Argument input error & goto :EOF)
echo %1 | findstr /i ":LLL" > nul && call %1 %2 %3 %4
goto :EOF

:LLL
echo %2 %3 %4

Trying to redirect a variable into a utility does not work, as you
probably figured out. Instead, send the string into FIND or FINDSTR
using and ECHO statement into a 'pipe' (|), as in the example above.
_____________________
Tom Lavedas

Jean Pierre Daviau

unread,
Dec 2, 2009, 11:35:29 AM12/2/09
to
@echo off
if "%1"=="" (echo Argument input error & goto :EOF)
echo %1 | findstr /i ":LLL" > nul && call %1 %2 %3 %4
goto :EOF

:LLL
echo %2 %3 %4

Trying to redirect a variable into a utility does not work, as you
probably figured out. Instead, send the string into FIND or FINDSTR
using and ECHO statement into a 'pipe' (|), as in the example above.
_____________________
Tom Lavedas

Although this does the job in that case. It would be great if that line
could take care of different inputs checking only for the colon. This will
be fine for a skeleton.cmd file.
:LLL 123
:SUB 123
:SOMETHINGELSE 123
:RANDOMSUB 123

with is done your line:

echo %1 | findstr /i ":" > nul && call %1 %2 %3 %4

Thanks Tom.

JPD

Tom Lavedas

unread,
Dec 2, 2009, 12:06:52 PM12/2/09
to

Better yet, it could check for just the valid subroutine names ...

set list=:LLL :SUB :SOMETHINGELSE :RandomSub
echo.%1 | findstr /i "%List%" > nul && call %1 %2 %3 %4
_____________________
Tom Lavedas

billious

unread,
Dec 2, 2009, 12:31:16 PM12/2/09
to

"Jean Pierre Daviau" <on...@wasenough.ca> wrote in message
news:ucqJlX2c...@TK2MSFTNGP06.phx.gbl...

We're faced with trying to devise a solution without knowing what you intend
to do.

Assuming that you're tring to run an internal subroutine IFF it exists, then
perhaps this may be of help:


This demonstration developed using XP
It may work for NT4/2K

----- batch begins -------
[1]@echo off
[2]findstr /b /i /r /c:"[ *:sub]" "%~f0" >nul&if not errorlevel 1 echo FOUND
& call :sub foundit
[3]call :sub hello
[4]goto :eof
[5]
[6] :sub
[7]echo found sub - %1
[8]goto :eof
------ batch ends --------

Lines start [number] - any lines not starting [number] have been wrapped and
should be rejoined. The [number] that starts the line should be removed

The label :eof is defined in NT+ to be end-of-file but MUST be expressed as
:eof

[6] : Note that the subroutine name need not begin in column 1.

[2] : To run an internal subroutine, we must examine the CURRENT batchfile,
the name of which is "%~f0"

Obviously, replace ':sub' on [2] with your destination routine name, or %n
as required.

Jean Pierre Daviau

unread,
Dec 2, 2009, 1:04:04 PM12/2/09
to

> We're faced with trying to devise a solution without knowing what you
> intend
> to do.
>
> Assuming that you're tring to run an internal subroutine IFF it exists,
> then perhaps this may be of help:


----random.cmd-----
echo %1 | findstr /i ":" > nul && call %1 %2 %3 %4


LLL
echo %2 %3 %4

goto :eof

:THISISASECRETSUB
echo %1
goto :eof
-------

Lets say I remember random.cmd but not wath is in it. I suppose there was
an echo in a sub there and I want to use it. Why ? Because I 'feel' for it
:o)
I take a chance and write at the prompt> random.cmd
:whatwasthenameofthissub "hello world"
Unfortunately it does not work. Ok I will write my hown echo line at the
prompt @echo "hello world"

Because I have a lot of energy and time to burn I could do:
at the prompt> for %I in (:LLL :SUB :SOMETHINGELSE :RandomSub) do call
random.cmd %I and this would work.

JPD

Jean Pierre Daviau

unread,
Dec 2, 2009, 1:16:29 PM12/2/09
to

> [2]findstr /b /i /r /c:"[ *:sub]"

Why the brackets and the in * [*:sub]

What is the use of the ! in !match%%b!

JPD

billious

unread,
Dec 2, 2009, 2:31:48 PM12/2/09
to

"Jean Pierre Daviau" <on...@wasenough.ca> wrote in message
news:%23zC4Su3...@TK2MSFTNGP04.phx.gbl...

[ and ] were left in inadvertantly.

Should have been /c:" *:sub"

(The regular expression
ANY number of spaces followed by the literal ':sub'

!match%%b! (in a different thread) means "the run-time value of the
environment variable 'match%%b' when DELAYEDEXPANSION mode is invoked.

eg:

setlocal enabledelayedexpansion
set var=original
for %%f in (1 2 3 4) do set var=%%f&echo %%f+%var%+!var!+

- try this line-sequence with and without the SETLOCAL line.

See

SETLOCAL /?

from the prompt for more docco - or see past responses in this ng. Note that
you may also need to use the ENABLEEXTENSIONS switch also.

This is a FAQ in alt.msdos.batch.nt - where you'd find hundreds of examples.


Todd Vargo

unread,
Dec 3, 2009, 6:32:45 PM12/3/09
to

If you don't remember the sub name, ISTM more practical to open the batch in
Notepad than looking for new ways to make blind guesses.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

Jean Pierre Daviau

unread,
Dec 4, 2009, 6:02:25 AM12/4/09
to
> If you don't remember the sub name, ISTM more practical to open the batch
> in
> Notepad than looking for new ways to make blind guesses.
>
I could have express this has I wanted a line with a second level of
abstraction, to create a basic squeleton.

If I create a squeleton.cmd.plate with only the first line:
@echo off

I could use it to avoid retyping the samething everytime I create a new cmd.
Chances are numerous that readers of this thread will point out THE case
where I will have to rem the line "(@echo off " for debugging or else.

Thanks for your attention Tod.

jp


0 new messages