V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
GTim
V2EX  ›  程序员

如何把 Mac OS 中的 shell 正在运行的日志重定向到文件?

  •  
  •   GTim · 2018-09-03 11:07:20 +08:00 · 2489 次点击
    这是一个创建于 2054 天前的主题,其中的信息可能已经有所发展或是发生改变。

    一时作死,启动命令时忘记把日志重定向到文件。

    吃完饭回来发现已经运行了好久,又不能关闭重来,直接导致电脑卡卡卡

    又没啥办法把正在运行的命令的输出重定向到文件?

    7 条回复    2018-09-03 20:45:57 +08:00
    winglight2016
        1
    winglight2016  
       2018-09-03 11:58:23 +08:00   ❤️ 1
    不明白你的意思?难道你的电脑卡是因为在命令行输出 log ?

    如果是因为长时间的任务卡,而任务又不能关闭,你除了忍着还有别的办法吗?
    v2exchen
        2
    v2exchen  
       2018-09-03 12:09:13 +08:00 via Android
    q397064399
        3
    q397064399  
       2018-09-03 14:10:28 +08:00
    cat /proc/{PID}/fd/1 是 0 还是 1 忘记了, 代表标准输入输出流文件 你可以看看
    q397064399
        4
    q397064399  
       2018-09-03 14:10:46 +08:00
    好吧.. 是 MacOS
    theworldsong
        5
    theworldsong  
       2018-09-03 14:14:38 +08:00
    xxxxxxxxxxxxxxxxx > yyyy.txt
    theworldsong
        6
    theworldsong  
       2018-09-03 14:15:13 +08:00
    没看题目。。。忽略我。
    nyanyh
        7
    nyanyh  
       2018-09-03 20:45:57 +08:00
    https://stackoverflow.com/questions/3425340/how-can-i-capture-the-stdout-from-a-process-that-is-already-running
    或者 sudo dtruss -f -p <PID> 2> stdout.txt
    dtrace 需要关闭 SIP,也就是说要重启一次,这一次跑的 stdout 是拿不到的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5346 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 09:00 · PVG 17:00 · LAX 02:00 · JFK 05:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.