交互式CLI promt,带PHP,无需回显到终端
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了交互式CLI promt,带PHP,无需回显到终端相关的知识,希望对你有一定的参考价值。
/** * Interactively prompts for input without echoing to the terminal. * Requires a bash shell or Windows and won't work with * safe_mode settings (Uses `shell_exec`) */ function prompt_silent($prompt = "Enter Password:") { if (preg_match('/^win/i', php_OS)) { $vbscript = sys_get_temp_dir() . 'prompt_password.vbs'; file_put_contents( $vbscript, 'wscript.echo(InputBox("' . addslashes($prompt) . '", "", "password here"))'); $command = "cscript //nologo " . escapeshellarg($vbscript); $password = rtrim(shell_exec($command)); unlink($vbscript); return $password; } else { $command = "/usr/bin/env bash -c 'echo OK'"; if (rtrim(shell_exec($command)) !== 'OK') { trigger_error("Can't invoke bash"); return; } $command = "/usr/bin/env bash -c 'read -s -p "" . addslashes($prompt) . "" mypassword && echo $mypassword'"; $password = rtrim(shell_exec($command)); echo "n"; return $password; } }
以上是关于交互式CLI promt,带PHP,无需回显到终端的主要内容,如果未能解决你的问题,请参考以下文章