开发者

bash output to file

开发者 https://www.devze.com 2023-03-01 04:00 出处:网络
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 fil开发者_C百科e \'out.asc\'. plz can yo

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 fil开发者_C百科e 'out.asc'. plz can you help me to redirect the output to file rather than screen. thanks in advance!


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消