【问题标题】:How to redirect output to file instead of printing on screen and run a python code, all in background?如何将输出重定向到文件而不是在屏幕上打印并在后台运行python代码?
【发布时间】:2014-08-15 13:43:12
【问题描述】:

以下是我的小python代码:

from __future__ import print_function

for i in range(0,10000):
     print (i**2)

要运行此代码,我在 Ubuntu 的终端中键入以下内容:

(time python trial_tail.py) & > trial_haha.t &

这不会将输出写入名为 trial_haha.t 的文件并将其打印在屏幕上。 如何让它写入文件而不是屏幕上并在后台运行?

谢谢 阿比纳夫

【问题讨论】:

  • 你试过 $(time python trial_tail.py > trial_haha.t) & 吗?
  • 谢谢,这会将输出写入文件。但是最后它会在屏幕上写下所花费的时间并等待我按Enter。我该如何避免呢?
  • 通过 &> 而不是 > 来重定向标准输出和标准错误;我不明白为什么它在最后等待输入
  • 添加 &> 具有相同的旧结果。我可以以某种方式也将花费的时间写入输出文件吗?

标签: python printing output tail


【解决方案1】:
{ time python trial_tail.py ; } &> trial_haha.t &

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-26
    • 1970-01-01
    相关资源
    最近更新 更多