|
Answer» Hi all
I am using the command
pkcs11-tool --module eTpkcs11.dll -L | findstr /v empty | findstr /b Slot > foo.txt
in a batch file. This writes the following into the txt file:
Slot 0 AKS ifdh 0
How can I store the result of the above command "pkcs.. ... Slot"> foo.txt in quotes into a variable instead.
Also more importantly how can I extract x the number SLot x (in this case x=0) from this string. Thanks guys.. findstr needs its search strings in quotes. Empty and slot in your case.
result of command OUTPUT...
for /f "delims==" %%V in (foo.txt) do set var=%%V
Try this to get the slot number
for /f "tokens=1,2 delims= " %%A in (foo.txt) do set num=%%B
Can I just say that I really hate that "foo" and "bar" stuff? Have done for years.
LOL sorry wont use em again. Now that I Have this elusive slot number how can i return that value to the script thats calling this batch file. SHould i simply echo it or return it some how. Im not SURE how variables are passed around using batch programming.
THanksSlightly fuller demo of what I wrote before...
Quote @echo off
REM (1) create test file echo Slot 0 AKS ifdh 0 > test.txt
REM (2) get whole line into a variable... REM delimiters are start and end of line for /f "delims==" %%V in (test.txt) do set line=%%V
REM (3) split the line into 5 tokens, delimiters being SPACES REM multiple spaces count as one REM shows how to select a particular TOKEN...
for /f "tokens=1,2,3,4,5 delims= " %%A in (test.txt) do (
REM Of course if you had already done (2) you could save a REM file read and do this instead... REM for /f "tokens=1,2,3,4,5 delims= " %%A in ("%line%") do (
set t1=%%A set t2=%%B set T3=%%C set t4=%%D set t5=%%E )
REM see results echo whole line... echo %line% echo. echo the line split up... echo %t1% echo %t2% echo %t3% echo %t4% echo %t5% the output is...
Quotewhole line... Slot 0 AKS ifdh 0
the line split up... Slot 0 AKS ifdh 0
To get the result from a called batch into a calling batch file you could do this in the called batch
Quotefor /f "tokens=1,2, delims= " %%A in (temp.txt) do echo %%B > num.txt Then when control returns to the calling batch, that file could contain a line eg
Quotefor /f "delims==" %%A in (temp.txt) do set num=%%A not solving your problem, as contrex has already done that, but just curious, what are you going to do once you get the output of pkcs into the variables? how are you going to use the slot numbers, or whatever that is returned from the command?
|