【问题标题】:Using nohup can I also redirect standard in?使用 nohup 我还可以重定向标准吗?
【发布时间】:2019-12-11 21:11:42
【问题描述】:

我可以像这样使用 nohup 存储 hive 查询的输出:

nohup hive -i transaction_testing.hive > nohup.out 2>&1 &

我的理解是 2>&1 将标准错误重定向到标准输出。

我的问题是,我是否也可以重定向标准,以便所有内容都在一个文件中?

A Google search shows me that in linux std in is 0.

我可以编辑上面的代码,在 nohup 文件中包含输入以及 std 错误吗?

例如假设 transactions_testing.hive 包含以下内容:

select *
from some_table
where fruits = 'apples';

我想在顶部输出包含此命令的文件以及下面的查询结果。

如果2>&1 将std 错误重定向到std out,0>&1 是否会对std in 做同样的事情?我如何将它们合二为一?

nohup hive -i transaction_testing.hive > nohup.out 0>1&2>&1 &

【问题讨论】:

  • 一个通常重定向stdin(注意“in”=“input”)来自 /dev/null,< /dev/null,虽然实际上不是,但实际上是关闭它。跨度>

标签: linux nohup


【解决方案1】:

0>&1 表示任何写入到标准输入的东西都将被发送到FD 1。但通常不会写入标准输入,它仅用于读取。

您可以简单地将输入文件复制到输出文件,然后在运行命令时附加到它。

cp transaction_testing.hive nohup.out
nohup hive -i transaction_testing.hive >> nohup.out 2>&1

【讨论】:

    猜你喜欢
    • 2011-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-25
    • 1970-01-01
    • 2021-12-25
    • 1970-01-01
    • 2013-12-05
    相关资源
    最近更新 更多