If you can do with the limit of not being able to use ? and * wildcard characters, I use a simple routine that leverages the command parser and FOR command.
Save this as
EchoArgs.cmd:
Code: Select all
@ For %%* in (%* %= Process each argument as a separate line. Arguments containing "poison"/whitespace must be quoted. =%
)do @ ECHO/%%~* %= Remove any quotes. Fails, by omission or substitution of filenames, arguments that contain * or ? =%
Use like this to write/ECHO each argument, removing any outer quotes [""], as a separate line:
[Call] EchoArgs.cmd [arg1 | "arg 1" [ arg2 | "arg=2" [...]]
- Supports many "poison" characters that normally would require escaping, including: & | < >
- Quotes are required for "poison" & | < > ^ and white-space characters: , ; = [space] [tab]
- Use command redirection as needed to create [>]/append [>>] to files
- LIMITATION: Ignores/expands arguments containing wildcard characters: ? *
Examples:
Write HTML lines
Code: Select all
>File.HTML Call echoArgs "<!DOCTYPE><HTML><HEAD>" "<TITLE>HTML file</TITLE>" "</HEAD><BODY>"
Resulting File.HTML:
Code: Select all
<!DOCTYPE><HTML><HEAD>
<TITLE>HTML file</TITLE>
</HEAD><BODY>
Append HTML lines
Code: Select all
>>File.HTML Call echoArgs "<H1>Heading</H1>" "<P>Text</P>" "</BODY></HTML>"
Appends to File.HTML:
Code: Select all
<H1>Heading</H1>
<P>Text</P>
</BODY></HTML>
Note: Above comments from others regarding code page may need to be adapted to produce technically valid HTML files.
Write .CSV lines [note outer quotes]
Code: Select all
Call echoArgs ""Item","Description","Price"" ""ABC","A b c","$1.00"" ""XYZ","X yz","$9.00"" >>File.CSV
Resulting File.CSV:
Code: Select all
"Item","Description","Price"
"ABC","A b c","$1.00"
"XYZ","X yz","$9.00"