dongmo6937 2015-04-15 11:03
浏览 399

php:使用exec命令而不输出到CLI

I am migrating a set of php scripts from Window 2003 / PHP 5.2 to Windows 2012 R2 / PHP 5.6.7

In the scripts exec commands are used, for example to copy files. Commands could look like this:

exec ('copy "C:\ftp\suppliername\upload\*.*" c:\somefolder\  >> output.log');

You could argue that there are better ways to copy files, but I rather wouldn't like to rebuild these scripts right now.

The problem I have is that when there are no files to copy, the error "The system cannot find the file specified." is now shown, while this wan't the case on the old server.

If you just execute the copy command on the command line, the output looks like this:

The system cannot find the file specified.
        0 file(s) copied.

This is the same as what gets written to output.log So apparently the "0 file(s) copied" is getting suppressed somewhere, but not the error.

So my question is, how do I get rid of the error on the commandline? I thought it would be some configuration in php.ini, but after comparing the php.ini from the old and the new server, I couldn't find any essential differences.

I've tried a few things to suppress the error, but with no success:

  • Adding a @ to the exec command
  • Adding ob_start() and ob_end_clean() before and after the command

Edit: please do not flag as a duplicate. I did see that question before asking my question. the answers given there do not solve my issue. The main question is, why was it working before, you would think that it should still be possible to get it working the same way without modifications to the scripts.

  • 写回答

3条回答 默认 最新

  • dpik71879 2015-04-15 11:09
    关注

    I suppose that this string is being printed to stderr. You could try to replace your STDERR as described in the post https://stackoverflow.com/a/3823015/146003.

    The essential part of the post consists of the lines:

    fclose(STDERR);
    (...)
    $STDERR = fopen('error.log', 'wb');
    

    You can then get rid of error.log. Although I didn't try, you could try to open NIL (see https://stackoverflow.com/a/313115/146003)

    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大