是否有任何方法可以将管道输出重定向为文件?
我使用 xmllint
来选择节点,我的测试目的 1.xml
看起来像
<resources>
<item>
<label>LABEL</label>
<value>VALUE</value>
<description>DESCRIPTION</description>
</item>
<item>
<label>LABEL</label>
<value>VALUE</value>
<description>DESCRIPTION</description>
</item>
</resources>
$ xmllint --xpath '/resources/item/value' 1.xml
<value>VALUE</value><value>VALUE</value>
上面的这个命令运行良好。
然后我尝试与管道|
结合,发生错误
$ cat 1.xml | xmllint --xpath '/resources/item/value'
Usage : xmllint [options] XMLfiles ...
...(help info)
我想原因是管道传输过程cat
的输出作为流,但是xmllint
只能接收文件路径作为参数。那么,有什么办法可以解决这个问题呢?或者也许有其他选择?
当然。如果我的猜测有错,指出真正的原因对我也很有帮助。
抱歉
我的英语很差。请原谅语法或打字错误。我正在尽力改进。
I'm use xmllint
to select node, and my test purposed 1.xml
is looks like this
<resources>
<item>
<label>LABEL</label>
<value>VALUE</value>
<description>DESCRIPTION</description>
</item>
<item>
<label>LABEL</label>
<value>VALUE</value>
<description>DESCRIPTION</description>
</item>
</resources>
$ xmllint --xpath '/resources/item/value' 1.xml
<value>VALUE</value><value>VALUE</value>
Command likes above is work well.
And then i try to combine with pipe |
, error occurred
$ cat 1.xml | xmllint --xpath '/resources/item/value'
Usage : xmllint [options] XMLfiles ...
...(help info)
I suppose the reason is pipe transmit process cat
's output as a stream, but xmllint
can only receive file path as argument. So, does any way to solve this problem? or maybe some alternative?
Of course. If my guess if fault, point at real reason is also pretty helpful to me.
sorry
My English is poor. Please excuse grammar or typing error. I'm trying my best to improve.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从未使用过
xmllint
,但来自其 手册页 , 我可以看到:因此,以下内容应该有效:
或者,如果您坚持输入应该来自标准输入,
I have never used
xmllint
, but from its man page, I can see:Therefore, the following should work:
or, if you insist that the input should come via stdin,
作为替代方案,您可以通过
--shell
选项将 xmllint 命令传递到 stdin或者
As an alternative, you can pass xmllint command to stdin via
--shell
optionOr