findstr

  • Thread starter Thread starter Jean Pierre Daviau
  • Start date Start date
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.

call :%1 %2 %3 %4
 
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
......
 
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
.....

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
 
@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
 
@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

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
 
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 said:
----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.

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.
 
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
 
Back
Top