AdamByrd wrote: ↑Thu Feb 15, 2018 7:15 pm
[*]Back to the first problem: how do I parse the input to the second batch instance line by line?
Use a nested FOR loop?
Or utilise the classic function'esque nature of a batch script, ala
this, for example.
delims in the example is a space
(replace with a ; comma; ,
(or any other delimiter if required and increment by one for every letter after %%I
for f "tokens=* delims= " %%I IN ('do a system command')
where ('x'), (i.e. x, is surround by single quotes)
or
for /f %%I IN (LIST.txt) do (
call :PROCESS %%I
)
goto :NEXT
:PROCESS
set Variable1 = %1
:: do something
goto :EOF
:NEXT
echo Continue main program
Notes:
call :PROCESS %%I
this can include any number of variables, i.e.
call :PROCESS %%I %%J %%K %%L %%M...
where %%I is the first variable for the "function" :PROCESS
(where the word PROCESS is equivalent to the name of a function)
(and where %%I to %%M represent the variables 1 thru 5, being passed to :PROCESS)
set VAR1 = %1
set VAR2 = %2
set VAR3 = %3
set VAR4 = %4
set VAR5 = %5
etc. etc.
Also, a note on the difference between a REM statement (meaning REMark) and ::
Lines commented out using :: are ignored by the pre-processor before the Batch script runs.
(Personally, I always use .cmd, vs .bat extensions)
Whereas a REM statement, is ignored by the pre-processor, and only determined to be a line to ignore on RUNTIME of the batch script.
(this means, the line is fully read, even though it is prefixed with a REM, and only after reading the line, does "DOS" ignore the line as a comment)
Also, at the start of a batch file, the first lines should be:
@echo off
setlocal
.. and the end of the file, where the :END lives should be:
:END
start notepad %REPORT%
endlocal
This is where the variable %REPORT% references a file such as %CD%\Report-%0.txt
%0 will display the name of the batch file being run, in this case:
vcvarsall.bat
P.S. I have 16 years+ of DOS batch file experience, and I'm still learning.
If you need help, send me a PM, I usually logon daily to see if there are any updates from Adam, Lyndsey, Josh
.. Just my 2 cents
*and anything to help you chill after a long day of banging your head into the plaster-board :)
EDIT: goddamn smileys ruin the layout of this post.. I recommend you edit the post to review what the actual Batch Script fcode is..
P.S. Where I use the FOR loop to:
call :PROCESS %%I
.. I can also say
call .\some_batch_file %%I;
and the script will then run a 2nd batch file whilst sending the variables %%I from the first batch file to %1 to the second batch file.
.. %%J in the first FOR loop becomes %2 variable in the 2nd batch file
.. %%K in the first FOR loop becomes %3 variable in the 2nd batch file etc. etc.
..
.. Then in the second batch file, you create a meaningful container for the information being parsed
set VAR1 = %1
set VAR2 = %2
set VAR3 = %3
then run the 2nd batch file using those variables as required
hope this helps your noodle
P.P.S. I so wanted to try the {for /f %I IN ('more')}, but then I realised I'm running Linux Mint, and I'm unable to do so :(
Going to have to wait until Monday when I'm back in work..
:wtf: