Home > front end >  Mute For-loop output
Mute For-loop output

Time:06-08

I have this for-loop batch to convert a bunch of text files to PDF. Sometimes there are literally thousands of files, which I do not want the output to fill up the log files.

How can I mute the output of this for-loop batch? I've tried placing 2>NUL in a few places, without much success.

SETLOCAL ENABLEDELAYEDEXPANSION
FOR %%F IN (D:\TEMP\FILE*.TXT) DO (
    SET TMPFILE=%%F
    SET NEWFILE=!TMPFILE:~0,-4!.PDF
    C:\EXE\txt2pdf.exe !TMPFILE! !NEWFILE! -PFS9
)

Thanks in advance!

CodePudding user response:

To prevent output of individual lines you can both turn echoing off individually for the line, using @, and prevent both stdOut and stdIn using command redirection 1> and 2>.

You can also completely remove SETLOCAL ENABLEDELAYEDEXPANSION, SET TMPFILE=%%F, and SET NEWFILE=!TMPFILE:~0,-4!.PDF, then change C:\EXE\txt2pdf.exe !TMPFILE! !NEWFILE! -PFS9 to "C:\EXE\txt2pdf.exe" "%%F" "%%~dpnF.PDF" -PFS9.

Essentially your entire batch file, (or single line if you have others), could look like this:

@For %%G In ("D:\TEMP\FILE*.TXT") Do @"C:\EXE\txt2pdf.exe" "%%G" "%%~dpnG.pdf" -PFS9 1>NUL 2>&1
  • Related