bash输出到文件

发布于 2024-11-04 09:05:15 字数 173 浏览 3 评论 0原文

我有以下语句

 for i in `cat i.txt`; do wine ~/run.exe $i.asc >> out.asc; done

,但它不断将所有输出写入控制台而不是文件“out.asc”。请您帮我将输出重定向到文件而不是屏幕。提前致谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

往日情怀 2024-11-11 09:05:15

可能是 wine 正在写入 stderr,因此您需要重定向:

for i in `cat i.txt`; do wine ~/run.exe $i.asc 2>> out.asc; done

注意 2>> 运算符中的 2,这意味着 stderr。

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.

余厌 2024-11-11 09:05:15

尝试将 stderr (2) 重定向到 stdout (1)

for i in `cat i.txt`; do wine ~/run.exe $i.asc >> out.asc 2>&1; done

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
给妤﹃绝世温柔 2024-11-11 09:05:15

也许您既有标准输出又有错误输出。使用 >>2>> 将两个输出流重定向到您的文件。

for i in `cat i.txt`; do wine ~/run.exe $i.asc >> out.asc 2>> out.asc; done

您可以选择将源重定向到不同的文件:

for i in `cat i.txt`; do wine ~/run.exe $i.asc >> out.asc 2>> err.asc; 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
顾铮苏瑾 2024-11-11 09:05:15

其他人已经回答了您的实际问题,我想展示一个更好的习惯用法来读取文件的行。

而不是

for i in `cat i.txt`; do
  : do something with $i
done

尝试

while IFS= read -r line; do
  : do something with "$i"
done < i.txt

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文