【问题标题】:make nohup write other than nohup.out使 nohup 写入 nohup.out 以外的内容
【发布时间】:2019-01-17 12:13:04
【问题描述】:

我一直在使用下面的命令来使 tail 写入 nohup.out 并在终端上打印输出。

nohup train.py & tail -f nohup.out

但是,我需要 nohup 来使用不同的文件名

当我尝试时

nohup python train.py & tail -F vanila_v1.out

我收到以下错误消息。

tail: cannot open 'vanila_v1.out' for readingnohup: ignoring input and appending output to 'nohup.out': No such file or directory

我也试过 nohup python train.py & tail -F nohup.out > vanila_v1.txt

然后它不会在标准输出上写入输出。

除了nohup.out,我如何让nohup 写?我不介意同时编写两个不同的文件。但是为了跟踪不同的过程,我需要不同的名称。 谢谢。

【问题讨论】:

    标签: bash shell nohup


    【解决方案1】:

    您需要为 nohup 命令传递 STDOUTSTDERR,例如:

    $ nohup python train.py > vanila_v1.out 2>&1 & tail -F vanila_v1.out
    

    此时,进程将进入后台,您可以使用tail -f vanila_v1.out。这是一种方法。

    这里有更多关于STDOUTSTDERR link 的信息。这是另一个 question,它使用 tee 命令而不是 > 一次性实现相同的目标。

    【讨论】:

    • 您好,感谢您的评论,但是当我尝试您的命令时,它不会在标准输出上打印出来。
    • 我之所以使用tail是为了在stdout上打印出来。
    • @Aaron 完整的命令行是nohup python train.py > vanila_v1.out 2>&1 & tail -F vanila_v1.out。这里有一个关键点,我认为你错过了:& 之前和之后的部分是完全独立的命令(第一个在后台运行)。因此,您将第一个命令的重定向作为第一个命令的一部分,并从第一个重定向到的任何位置读取第二个 (tail) 命令。
    猜你喜欢
    • 1970-01-01
    • 2011-12-22
    • 2018-02-15
    • 1970-01-01
    • 1970-01-01
    • 2014-08-30
    • 1970-01-01
    • 2012-05-11
    相关资源
    最近更新 更多