php:如何从命令行重新运行脚本?

问题描述:

我有一个解析csv文件的脚本。当脚本完成时,它返回到命令提示符。php:如何从命令行重新运行脚本?

我想要做的是当脚本完成时询问用户是否要重新运行它,用户输入“yes”或“no”,yes重新运行并且不存在脚本。

我该怎么做呢?

+0

'$ rerun_flag = TRUE; ($ rerun_flag){$ rerun_flag = false; //请求重启} else {//终止}' –

+0

这一切都很有意义,它要求重新启动并捕获用户输入,我不知道该怎么做 – user1532669

+1

好吧,如果它是命令行[阅读此] (http://php.net/manual/en/features.commandline.io-streams.php) –

这是我来到了解决方案:

$rerun_flag=true; 
while($rerun_flag == true){ 
    //do stuff 

    echo "\n\nDo you wish to rerun? Enter 'yes' or 'no' without quotes: \n\n"; 
    $rerun_flag=false; 
    $line = trim(fgets(STDIN)); // reads one line from STDIN 
    if($line == 'yes'){ 
     $rerun_flag=true; 
    } else { 
     $rerun_flag=false; 
     exit; 
    } 
}