【问题标题】:save exec() output to file in将 exec() 输出保存到文件中
【发布时间】:2015-07-27 16:38:00
【问题描述】:

我正在使用exec() 函数通过php 在debian 服务器上执行gzip

gzip -1 -c file1.xxx > file1.gz  

现在我想将错误保存在一些 error.log 中。

  1. 如何设置输出到文件?
  2. 使用shell_exec()会更好吗?

【问题讨论】:

    标签: php shell debian exec gzip


    【解决方案1】:

    要将stderr 重定向到文件,请使用2> 重定向器(2 是标准错误的文件句柄):

    gzip -1 -c file1.xxx >file1.gz  2>error.log
    

    (另请参阅重定向部分man bash

    【讨论】:

    • 谢谢。我正在尝试这种方式,但我对文件没有权限......是否有可能保存到 error.log 执行的命令?
    • 并且在 error.log 中缺少信息...当我为 ex 运行命令时。 nonsense 2>&1 我进入浏览器 -> sh: 1: 废话:未找到但如果我在错误日志中运行 nonsense 2>error.log -> sh: 1: bad: not found...
    猜你喜欢
    • 1970-01-01
    • 2019-06-14
    • 1970-01-01
    • 2020-12-29
    • 2016-02-28
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 2015-08-07
    相关资源
    最近更新 更多