bash 中重定向的详细信息(特别是 Cygwin)
我想知道是否有人可以向我指出处理 bash 中输出重定向如何工作的低级机制的资源。 不幸的是,我只能打开基本的“>将输出发送到文件”指南的一页又一页,但似乎没有什么比这更详细的了。
特别是,我面临着一种奇怪的情况,即在 Cygwin 上使用附加重定向器 (>>) 有时似乎从文件开头开始覆盖目标,而不是按预期从末尾附加。 我不知道 bash 可以提供任何命令组合来故意执行此操作,但我想更好地了解重新定向的实际处理方式,以便尝试调试此行为并找出可能的情况造成它。
实际的输出来自一个 Java 程序,该程序通过 System.out.println() 输出直接的进度消息,以防这里可能出现我不知道的问题
I'm wondering if anyone can point me at resources dealing with the low(ish) level mechanics of how output rediction works in bash. Unfortunately, I've only been able to turn up pages and pages of the basic "> sends output to a file" guides, but nothing seems to go into more detail than that.
In particular, I'm facing a strange situation whereby using the append redirector (>>) on Cygwin sometimes seems to start overwriting the target from the beginning of the file, rather than appending from the end as expected. I'm not aware of any combination of commands that can be given from bash to do this deliberately, but I wanted to get a better understanding of how the reidrection is actually handled in order to try and debug this behaviour and figure out what might be causing it.
The actual output is from a Java program that outputs straightforward progress messages via System.out.println(), in case there could be a gotcha here I'm not aware of
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道这在 Cygwin 中是否是这样工作的,但通常这种事情使用:
“>”的区别 和“>>” 通常通过为 open 命令提供不同的标志来处理; 对于“>”,仅打开文件,而对于“>>” 文件以追加模式 (O_APPEND) 打开。
我怀疑Cygwin对原始BASH源代码进行了任何重大更改,因此我怀疑您所遇到的情况可能与Cygwin在WIN32上实现这些UNIX功能有关。
I don't know if this is how it works in Cygwin, but usually this kind of thing uses:
The difference between ">" and ">>" is usually handled by giving different flags to the open command; for ">", the file is merely opened, while for ">>" the file is opened in append mode (O_APPEND).
I doubt that Cygwin has made any significant changes to the original BASH source code, so I suspect that what you are experiencing may be related to Cygwin's implementation of these UNIX functions on WIN32.