1.

Solve : logging defrag output?

Answer»

I'm trying to create a batch file to defrag my drives. The code is:

for /f "tokens=2-4 delims=/ " %%a in ('date /t') do set today=%%c%%a%%b
defrag e: /v/f >D:\original_programs\utilities\batch_files\defrag_e_report_%today%.txt (this line is repeated for each drive)

The code runs fine from a command prompt. But when I run it from a batch file, extra text ".txt 1" is mysteriously inserted. The output and error is SHOWN below.

D:\original_programs\utilities\batch_files>defrag e: /v/f .txt 1>D:\original_pr
ograms\utilities\batch_files\defrag_e_report_20051225

Two or more parameters that could be a volume exist.
There can be only ONE drive letter or volume mount point parameter.

If I remove the reference to the date, the line item works, but extra text "1" is also mysteriously added. The output is shown below.

D:\original_programs\utilities\batch_files>defrag e: /v/f 1>D:\original_program
s\utilities\batch_files\defrag_e_report.txt

If I don't log the output, I don't receive the extra text and the error. Anybody know how to fix this or what is going on? Is there another way to log the output. (BTW, I don't want to buy Diskkeeper for those salesmen out there.)If you had quoted the output data set name, you would notice it resolves as:

Code: [Select]
"D:\original_programs\utilities\batch_files\defrag_e_report_%today% .txt"


You could try this for the fix:

Code: [Select]
for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (
defrag e: /v /f > D:\original_programs\utilities\batch_files\defrag_e_report_%%c%%a%%b.txt
)


You can stack as many defrag statements inside the close PAREN as you need.

Most commands PRODUCE two output datastreams.The 1> is notation for STDOUT; 2> would be for STDERROR. This allows you to create two redirected files. SORTA like good file, bad file.

Hope this helps.

I am not now, nor have I ever been, a member of the Diskeeper sales force.Thanks, the quotes worked.



Discussion

No Comment Found