简体   繁体   English

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

[英]php: How can I rerun a script from the command line?

I have a script that parses a csv file. 我有一个解析csv文件的脚本。 When the script completes it returns to the command prompt. 脚本完成后,将返回到命令提示符。

What I want to do is when the script finishes it asks the user if they want to rerun it, the user enters "yes" or "no", yes reruns it and no exists the script. 我想做的是在脚本完成时询问用户是否要重新运行它,用户输入“是”或“否”,是,则重新运行它并且不存在该脚本。

How would I go about doing this? 我将如何去做呢?

This is the solution I arrived at: 这是我到达的解决方案:

$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;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM