>我需要从split bash命令中获取结果以在php中构建exec文件。
例:
我的文件: 1
我的 bash 命令:
split 1 -l 10 test -a 4
现在我得到了更多示例文件,例如:
Testaaaa, Testaaab, Testaaac,
我需要结果,因为有了这个结果,我需要构建一个看起来像这样的文件:
php file.php testaaaa ;
php file.php testaaab ;
php file.php testaaac ;
...
有什么办法可以做到这一点吗?
如果您知道拆分文件名的前缀是什么(以 $prefix
为单位),则可以使用以下方法获取所有文件名的列表:
# 4 = suffix length, change this if you change -a argument to split
$pattern = $prefix . str_repeat("?", 4);
$files = glob($pattern);
$files
将设置为包含所有匹配文件名的数组。
我认为php的exec
函数可以做到这一点:
$output = exec('split 1 -l 10 test -a 4');
// then do whatever you like with the result of the command presented in $output
解决方案:
echo "[+] Start spliting...'n";
exec("split 1 -l 800 split -a 4");
exec("ls | grep split", $op);
exec("rm -rf mass");
$file = fopen('mass', 'a');
foreach(array_values($op) as $line) {
fwrite($file, 'php crawler ' . $line . ' ; ' . PHP_EOL);
}
fclose($file);