2016-02-03 56 views
0

我使用MySQLConverterTool的cli.php将ext/mysql函数转换为ext/mysqli。如果我一次只转换一个文件,它在命令行上可以正常工作,但我想要自动化该过程以转换文件数组。脚本来自动化MySQLConverterTool的cli.php

我得到的PHP文件有: 查找/路径/到/目标/目录下的* .PHP> php_files.txt

这里是我的process_cli.php脚本:在

#!/usr/bin/php 
<?php 
    $files = file('/path/to/php_files.txt'); 

    foreach ($files as &$file) 
    { 
     // cli.php -f $file -u; // returns "unexpected '$file' (T_VARIABLE)" 

     // echo $file; // works 

     shell_exec("php cli.php -f $file -u"); // returns "sh: 2: -u: not found" with no files converted 
} 
?> 

任何想法如何正确工作?在环路从var_dump($file)


结果:

string(35) "/home/bill/orderstatus/sync_db.php " ... string(48) "/home/bill/orderstatus/templates/searchForm.php " string(59) "/home/bill/orderstatus/templates/orderDetailRegistered.php " string(36) "/home/bill/orderstatus/database.php " string(33) "/home/bill/orderstatus/index.php " 
+0

你的'foreach'不工作?您必须拥有每个'$ file'的完整路径才能对其执行操作。 –

+0

是的,该foreach正在工作;注意echo $文件;作品和$ files数组包含每个文件的完整路径。 – Bill

+0

您是否尝试过不通过参考传递文件? –

回答

0

得到这个工作。

我添加了一个str_replace来摆脱$ files条目中的尾部空格,并简单地在f参数之前移动了u参数。

#!/usr/bin/php 
<?php 
    $files = file('/path/to/php_files.txt'); 

    foreach ($files as $file) 
    { 
    $file = str_replace(' ', '', $file); 
    shell_exec("/usr/bin/php cli.php -u -f $file"); 
    } 
?>