Pergunta
i have the following statement
for i in `cat i.txt`; do wine ~/run.exe $i.asc >> out.asc; done
but it keeps writing all the output to console not the file 'out.asc'. plz can you help me to redirect the output to file rather than screen. thanks in advance!
Solução
It might be that wine is writing to stderr, so you need to redirect that:
for i in `cat i.txt`; do wine ~/run.exe $i.asc 2>> out.asc; done
Notice the 2 in the 2>>
operator, this means stderr.
Outras dicas
try with redirecting stderr (2) to stdout (1)
for i in `cat i.txt`; do wine ~/run.exe $i.asc >> out.asc 2>&1; done
Maybe you have both a standard output and erro outputs. Use >>
and 2>>
to redirect both output stream to your file.
for i in `cat i.txt`; do wine ~/run.exe $i.asc >> out.asc 2>> out.asc; done
You could optionally redirect sources to different files:
for i in `cat i.txt`; do wine ~/run.exe $i.asc >> out.asc 2>> err.asc; done
Other have answered your actual question, I'd like to show a better idiom to read the lines of a file.
Instead of
for i in `cat i.txt`; do
: do something with $i
done
Try
while IFS= read -r line; do
: do something with "$i"
done < i.txt
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow