php - PHP exec() 运行代码但不能完全工作
问题描述
在我的代码的某些部分,我比较了 2 个文件并使用exec()
函数将差异输出到另一个文件。
在exec
我使用的功能中comm -13 <(sort file_a) <(sort file_b) > output
当我运行我的 php 代码时,它会创建输出文件,但文件本身是空的。当我直接将命令复制并粘贴到终端时,它还会填充具有差异的文件,但不会在 php.ini 上填充我的输出文件。
部分代码;
exec('bash -c \'comm -13 <(sort "' . $path_d_raw.$least_recent_raw_file . '") <(sort "' . $path_d_raw.$most_recent_raw_file . '") > test.txt 2>&1\'', $output, $return);
$path_d_raw.$least_recent_raw_file and $path_d_raw.$most_recent_raw_file
路径正确,/file 对其进行了一百次测试。
我也尝试过,shell_exec
但无法以任何方式完成。
解决方案
您可以使用 filesize() 函数直接比较文件大小,也可以回显该值。
<?php
// outputs e.g. somefile.txt: 1024 bytes
$filename = 'somefile.txt';
echo $filename . ': ' . filesize($filename) . ' bytes';
?>
推荐阅读
- java - 尝试针对 OAuth 2 服务器 UAA 对 RabbitMQ 进行身份验证
- graphql - 我怎样才能使这个graphql挤压文件夹样式工作
- button - 带按钮的菜单
- python - Python string_grouper 中的 match_most_similar 返回原始字符串
- c++ - 为什么我在运行此代码后会出现以下问题?在抛出 'std::bad_alloc' what() 的实例后调用终止:std::bad_alloc
- c# - Active Directory 对象已经存在,使用 SetPassword 和新对象 []{}
- bash - 如何将 ```zenity --password``` 输入到变量中?
- javascript - 使用 Typescript 从字符串中获取特定字符
- assembly - 多周期数据路径中固定的 RegWrite 控制信号的影响?
- python - 如何创建距离矩阵