在composer包中,我有post-install-cmd脚本,如下所示:
#!/bin/bash
echo 'Hello!'
read -p 'Database password: ' DB_PASS
php setup/index.php database_password=$DB_PASS
echo 'Complete!'
但在composer install
之后我收到了这个错误:
...
Generating autoload files
> post-install-cmd: _scripts/ask_db_data.sh
Executing command (CWD): _scripts/ask_db_data.sh
Hello!
Script _scripts/ask_db_data.sh handling the post-install-cmd event returned with an error
[RuntimeException]
Error Output: Hello!
Exception trace:
() at phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:196
Composer\EventDispatcher\EventDispatcher->doDispatch() at phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:94
Composer\EventDispatcher\EventDispatcher->dispatchScript() at phar:///usr/local/bin/composer/src/Composer/Installer.php:350
Composer\Installer->run() at phar:///usr/local/bin/composer/src/Composer/Command/InstallCommand.php:134
Composer\Command\InstallCommand->execute() at phar:///usr/local/bin/composer/vendor/symfony/console/Command/Command.php:256
Symfony\Component\Console\Command\Command->run() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:838
Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:189
Symfony\Component\Console\Application->doRun() at phar:///usr/local/bin/composer/src/Composer/Console/Application.php:167
Composer\Console\Application->doRun() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:120
Symfony\Component\Console\Application->run() at phar:///usr/local/bin/composer/src/Composer/Console/Application.php:98
Composer\Console\Application->run() at phar:///usr/local/bin/composer/bin/composer:43
require() at /usr/local/bin/composer:25
如何在作曲家脚本中询问用户输入?
答案 0 :(得分:3)
好的,您正在尝试执行bash / shell脚本来读取字符串并将其传递给您的php文件。我不确定,为什么这样做不成功。
另一种方法是保留post-install-cmd
的PHP代码。
这是一个事件,它可以访问Composer和IO。
要使用控制台,您需要Composer中的$io
对象。
您可以使用getIO()
获取它。
然后,您可以使用方法ask()
或askConfirmation()
以交互方式询问用户“缺失”值。
非常简短:
$io = $this->getIO();
$pw = $io->ask('Enter your Password: ');
exec('php setup/index.php database_password=' . escapeshellarg($pw));
答案 1 :(得分:0)
从用户那里获取输入的一种方法是将数据放入文件并在bash脚本中读取它:
<tr>
...static row columns are here...
</tr>
<tr ng-repeat:"rowItem in rowItems track by $index">
...rest of row here...
</tr>