Question

I have a windows batch file, which iterates over files in a folder and runs a command on each file. Specifically I am running xmllint to validate some files:

for %%i in (c:\temp\*.xml) do (
   C:\XMLLINT\xmllint -noout -schema "C:\schemas\schema.xsd" "%%~dpnxi" >> c:\output.txt
)

It currently shows the output on screen. I want to show the output of all these commands placed in an output file. How can I achieve this? By using the append operator (>>) nothing is accomplished except for a blank file being created.

Is it because of xmllint?

Was it helpful?

Solution

If you're trying to redirect error output from the program, it might be writing to stderr. You can try to redirect it with:

for %%i in (c:\temp\*.xml) do (
   C:\XMLLINT\xmllint -noout -schema "C:\schemas\schema.xsd" "%%~dpnxi" >> c:\output.txt 2>&1
)

Basically the 2>&1 at the end means redirect anything from stderr (which is 2) to stdout (which is 1). Since stdout is redirected to a file, you should now see the stderr stream in the file. Hope this works for you!

OTHER TIPS

I've never used it, but if its documentation is here, have you tried just removing your "-noout" option, or adding an: "-output c:\output.txt"?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top