Home > OS >  Output command result to file
Output command result to file

Time:04-14

Windows cmd file has the following line

  wget "http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz" -P C:\temp >> dld.log

After executing the dld.log file is empty. What is wrong with output redirection? It is necessary that the output of wget execution is written to the dld.log file

CodePudding user response:

wget redirects output to stderr mostly to split off from the results data.

So direct answer to to make the current redirect code work is to use 2>&1 to direct sterr stream to stdout as in:

(wget "http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz" -P "C:\temp")>>dld.log 2>&1

However, wget has log functions built in which makes more sense. The switch is --output-file

wget "http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz" -P "C:\temp" --output-file=dld.log

See the wget manual for more info.

  • Related