2015-12-20 110 views
4

在作曲家包我已經安裝-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 

我怎麼能問用戶輸入作曲家腳本?

回答

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腳本閱讀:

#!/bin/bash 
source .env