How to Pass Variable value in an argument using batch script

133 views Asked by At

I am implementing a tool on Beyond Compare. I have this code that reads the content of a file and store in a variable

for /f "usebackq tokens=* delims=" %%h in ('type C:\user\userfiles\title.txt') do (
set title=%%h
)

Example contents of title.txt

AAA BBB CCCC

Now I want to pass the value of %title% in this code

%varA% %varB% c:\user\output1\%%a c:\user\output2\%%b "c:\user\report.html" %title% /silent

To elavorate:

c:\user\output1\%%a    -> %1
c:\user\output2\%%b    -> %2
"c:\user\report.html"  -> %3
%title%                -> %4

Now, This files.txt will call the arguments above as a part of the script's arguments.

file-report layout:side-by-side options:display-all,line-numbers title:%4 output-to:%3 output-options:html-color %1  %2 

Now the problem is, when i perform an echo for %title% it displays "AAA BBB CCC" but when on this line of code,

%varA% %varB% c:\user\output1\%%a c:\user\output2\%%b "c:\user\report.html" %title% /silent

It only reads the first word before the first space which is "AAA"

I already tried to enclosed with double quotes ("%title%") but im getting the "The system cannot find the file specified."

1

There are 1 answers

4
Magoo On

Since you appear to be calling a procedure with your parameters (but haven't shown us the call) we're forced to make assumptions.

My guess would be:

in the call line: ..... "%title%"

Within the procedure, use %~4 in place of %4.

But without knowing what the syntax is of whatever utility may be being used, there's no guarantee.