duanning9110 2011-06-30 12:03
浏览 45

在将输出重定向到文本文件时使用exec似乎锁定了所述文件

On a WAMP configuration, I am executing a shell command with exec and redirecting the output with >> log.txt. The commando is called many times in the script. The first time, the file is created, and the first output is written on it, but it seems the file stream is not closed (I can't delete the file, and Windows tells me that the file is opened by somebody else), and as such the script try to continue loading but do nothing else, and is still try after the 5 minutes limit I set for this script.

Am I doing something wrong? If yes why? Otherwise where does the problem lies?

EDIT: I've confirmed that by commenting the code line that it is the source of my problem. Furthermore, although I interrupted the script, the file remained locked to any change (edit/move/delete).

EDIT 2: Using pclose(popen("start /B ". $cmd, "r")) instead, as suggested in this comment doesn't seems to bring anything, regardless If I use >> log.txt or not.

EDIT 3: After a forced unwanted reboot of the server, the issue isn't there anymore.

I've talked with some colleague which encountered a similar problem with their application, and they said that rebooting their server always "solved" the problem. But I don't call that a solution if the problem comes again sooner or later. So it seems that the "silent update" scenario is the more possible.

In the meantime the server will be migrated to a machine with a newer OS (Windows 2008 Server). I'll wait and see if the problem comes again, but if possible I would like to takes measures so I don't have to deal with it in the future.

  • 写回答

1条回答 默认 最新

  • douliang6563 2011-07-25 20:53
    关注

    why dont you exec($cmd, $output, $result) ? this will return the output in the $output variable. you can then do a file_put_contents($file, implode(" ", $output), FILE_APPEND)

    this will let you append the output of the command right into the log file in pure php way

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条