laravel artisan use of undefined constant STDIN - assumed 'STDIN' infinite loop
Asked Answered
S

5

12

I am using laravel 5.6 and have the problem, when I use the command "php artisan vendor:publish" in the console, I get the following error:

[ERROR] Use of undefined constant STDIN - assumed 'STDIN'
Which provider or tag's files would you like to publish?
 [0] Publish files from all providers and tags listed below
 [1] Provider: Intervention\Image\ImageServiceProviderLaravel5

The problem is, that these messages appear infinite, until I close the console or after a long time it kills the process.

I looked for this issue on google, but only found the problem with stdin and the difference is, that the people who had that problem, didn't call artisan in the command line interface, but directly in a php script.

The same problem appears when I use "php artisan migrate"

Spooner answered 10/4, 2018 at 6:6 Comment(10)
Have you altered any files in the vendor folder? Might be worth doing a composer update just in case.Sip
No, not manually. All changes were made with composerSpooner
If you try running composer update and then running the vendor:publish command does that make any difference?Sip
I tried "composer update" several times, unfortunately it doesn't make any difference. I was using laravel 5.5 before and because the problem appeared, I thought it would be an idea to upgrade laravel to 5.6, but that also didn't make any difference.Spooner
I am just wondering if there is a package you've installed which is causing this. Would you be able to share your composer show -i output?Sip
pastebin.com/hR8yMw57Spooner
Could you pastebin your composer.json?Sip
Try composer dump-autoload beforehand.Soidisant
pastebin.com/fvuvSfNvSpooner
I tried composer dump-autoload before, but it didn't make any differenceSpooner
S
13

I have found a solution for the problem:

I had to add the following line to the artisan file (in the laravel directory).

define('STDIN',fopen("php://stdin","r"));

Now it works.

It's still strange, because normally artisan should work out-of-the-box, without the need to change anything.

Spooner answered 12/4, 2018 at 13:43 Comment(4)
To avoid issues in all environments you should use if(! defined('STDIN')) define('STDIN', fopen("php://stdin","r"));Journeyman
I tied this fix but it aint working. It still says use of undefined constsnt STDINExpectoration
If someone is wondering where to put this code, Then public/index.php is the place. Still not sure why it doesn't work out of the box.Sestos
Didn't work with meIgnatz
U
16

I was getting the issue mentioned above while running artisan command to seed the db tables: Artisan::call('db:seed', [...]) while in production. Adding the --force flag fixed my issue

Artisan::call('db:seed', [
   '--force' => true
])

Make sure you use --force flag if you are in production.

Unsophisticated answered 19/3, 2020 at 22:1 Comment(0)
S
13

I have found a solution for the problem:

I had to add the following line to the artisan file (in the laravel directory).

define('STDIN',fopen("php://stdin","r"));

Now it works.

It's still strange, because normally artisan should work out-of-the-box, without the need to change anything.

Spooner answered 12/4, 2018 at 13:43 Comment(4)
To avoid issues in all environments you should use if(! defined('STDIN')) define('STDIN', fopen("php://stdin","r"));Journeyman
I tied this fix but it aint working. It still says use of undefined constsnt STDINExpectoration
If someone is wondering where to put this code, Then public/index.php is the place. Still not sure why it doesn't work out of the box.Sestos
Didn't work with meIgnatz
V
6

Add

if(! defined('STDIN')) define('STDIN', fopen("php://stdin","r"));

to your index.php file. I tried adding this to artisan file but didn't work but placing it in index.php did the trick. My PHP version is v. 7.4 on Ubuntu 18.04

Voltmeter answered 24/9, 2020 at 9:18 Comment(0)
C
3

This problem is caused by application environment. Change application env to local or add --force parameter after artisan command.

Canton answered 9/1, 2022 at 13:41 Comment(0)
T
0

One thing to check is to ensure you are running the correct version of PHP for the version of Laravel.

php -v will show the php version

I was surprised to see that for me, the CLI version of PHP (which is what artisan uses) was really old.

I didn't realize my shared host had many different versions of PHP installed.

I was able to run artisan commands by using the command corresponding to the PHP version I needed to use: php7.1 artisan migrate

Turbojet answered 29/5, 2018 at 9:47 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.