Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php artisan schedule:run does not work in windows #7868

Closed
uwascan opened this issue Mar 4, 2015 · 24 comments
Closed

php artisan schedule:run does not work in windows #7868

uwascan opened this issue Mar 4, 2015 · 24 comments

Comments

@uwascan
Copy link

uwascan commented Mar 4, 2015

I am trying out the new command scheduling feature of Laravel 5 on windows 7 using a windows based cron service [http://www.intelliadmin.com/index.php/2011/11/cron-service-for-windows/]. When I discovered that my commands where not running I ran php artisan schedule:run manually on a console and got the following error: Running scheduled command: C:\Program Files (x86)\PHP\v5.6\php.exe artisan roman:inspire > /dev/null 2>&1 &
The system cannot find the path specified.
I think the problem is with '> /dev/null 2>&1 &' appended to the command. Is it possible for laravel not to append '> /dev/null 2>&1 &' when running on windows, if not what do you suggest I do. I have an up coming project that depends on the command scheduling feature of Laravel 5.
Any guidiance will be appreciated.

@GrahamCampbell
Copy link
Member

This is known, yeh. Looks like windows isn't supported.

@crynobone
Copy link
Member

@uwascan
Copy link
Author

uwascan commented Mar 5, 2015

I commented out the part the method 'buildCommand' in Illuminate\Console\Scheduling\Event.php as shown below
/**
* Build the comand string.
*
* @return string
*/
public function buildCommand()
{
$command = $this->command; //.' > '.$this->output.' 2>&1 &';
return $this->user ? 'sudo -u '.$this->user.' '.$command : $command;
}

my scheduled jobs are running now. this is a terrible thing to do I know, it will remain so until I come across a better solution.

@uwascan
Copy link
Author

uwascan commented Mar 5, 2015

Is there any best practice on how to extend or replace Illuminate\Console\Scheduling\Event.php?

@uwascan
Copy link
Author

uwascan commented Mar 5, 2015

@GrahamCampbell your response is not good enough, are you saying windows users should avoid Laravel?

@neomerx
Copy link

neomerx commented Mar 5, 2015

@uwascan you're right on your way to make a pull request to Laravel however manipulation is a surplus

btw why running PHP on windows servers these days?

@uwascan
Copy link
Author

uwascan commented Mar 5, 2015

From the link posted by @crynobone, I was able to make it work on windows using
php artisan schedule:run > NUL 2>&1

@crynobone
Copy link
Member

btw why running PHP on windows servers these days?

Someone/team could consider http://azure.microsoft.com/en-us/, unless Laravel team has decided not to support Windows.

@uwascan
Copy link
Author

uwascan commented Mar 5, 2015

@neomerx my client only has windows based infrastructure. I think PHP support on windows is not as bad as it is portrayed to be. What would you do if you are hired by a windows shop to build a php app? reject the offer or force linux? I find Linux very good though, I am still wrapping my head around it.

@neomerx
Copy link

neomerx commented Mar 5, 2015

@uwascan Cos not unless you're a hardcore windows hater :) However if a company rents servers or cloud infrastructure (which is very common these days for internet web projects) typically it's *nix based. Thus worth asking.
Anyway having your pull request with something like php_uname('s') === 'WINNT' ? ... : ...; would be 👍

@neomerx
Copy link

neomerx commented Mar 5, 2015

@uwascan
Copy link
Author

uwascan commented Mar 5, 2015

The project I am working is used internally on a private LAN. I submitted a pull request a few hours ago. My very first. #7887

@uwascan
Copy link
Author

uwascan commented Mar 7, 2015

Another simple way to make this work on windows without changing Laravel code is to append the following to your sheduler code

->sendOutputTo('NUL')

Example

$schedule->command('inspire')->cron('*/1 * * * * *')->sendOutputTo('NUL');

the code below works on windows when sending output to a file.

$schedule->command('inspire')
    ->cron('*/1 * * * * *')->sendOutputTo(storage_path('logs/output.log'));

This is what I am currently using and all is good so far. I think this should be added to the docs.

@gregrobson
Copy link

Thank you @uwascan - it's 11:50pm, and that's just helped me with local testing. Works perfectly on windows.

@dnetix
Copy link

dnetix commented May 25, 2015

Why is this issue closed, still not fixed. I am just removing the "2>&1 &" string from the Laravel code but it's not a good solution. And the modification to the Laravel code should not be so hard. Just put a conditional if the server OS is windows do not append that string. I prefer linux servers, always, but you cannot ask to a client to change all his infrastructure.

@Tropicalista
Copy link

I found this solution on laracast and works pretty well: https://laracasts.com/discuss/channels/general-discussion/running-schedulerun-on-windows

@cvlug
Copy link

cvlug commented Nov 25, 2015

The solution on https://laracasts.com/discuss/channels/general-discussion/running-schedulerun-on-windows does not work for me: nothings happens.
I tried uwascan solution.
In taskplanner, in field Program/script, i put: php
In field Add arguments, i put: D:\phpsites\touristpreview\laravel\artisan schedule:run > NUL 2>&1
In log files i then see:

[2015-11-25 16:00:19] local.ERROR: exception 'RuntimeException' with message 'Too many arguments.' in D:\phpsites\touristpreview\laravel\vendor\symfony\console\Input\ArgvInput.php:177
Stack trace:
#0 D:\phpsites\touristpreview\laravel\vendor\symfony\console\Input\ArgvInput.php(86): Symfony\Component\Console\Input\ArgvInput->parseArgument('>')
#1 D:\phpsites\touristpreview\laravel\vendor\symfony\console\Input\Input.php(61): Symfony\Component\Console\Input\ArgvInput->parse()
#2 D:\phpsites\touristpreview\laravel\vendor\symfony\console\Command\Command.php(221): Symfony\Component\Console\Input\Input->bind(Object(Symfony\Component\Console\Input\InputDefinition))
#3 D:\phpsites\touristpreview\laravel\vendor\laravel\framework\src\Illuminate\Console\Command.php(136): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 D:\phpsites\touristpreview\laravel\vendor\symfony\console\Application.php(838): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 D:\phpsites\touristpreview\laravel\vendor\symfony\console\Application.php(189): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Console\Scheduling\ScheduleRunCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 D:\phpsites\touristpreview\laravel\vendor\symfony\console\Application.php(120): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 D:\phpsites\touristpreview\laravel\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(107): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 D:\phpsites\touristpreview\laravel\artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 {main}

Anybody please have a solution?

@DarioCorno
Copy link

I'm actually using Windows 10, and it works if the batch file is written like this :

php artisan schedule:run 1>> NUL 2>&1

also redirectin ghte output to some sort of log works fine

php artisan schedule:run >> schedule_logs.log

@javedLive
Copy link

javedLive commented Aug 22, 2016

@DarioCorno How did you create the batch file and where did you put that?

for me I have done the following way ..But cron doesn't work so far:
I have created a batch file with name cron.bat ( scheduler array I want to send email to list of user) and put it inside of my blog (project name)
I wrote the following line inside of batch file
php artisan schedule:run 1>> NUL 2>&1

The I have run the following command in my cmd to create the task in schedule:

schtasks /create /sc minute /mo 1 /tn "PHP Cron Job" /tr C:\xampp\htdocs\blog\cron.bat

It said PHP cron job crated successfully.

But nothing happened it every minute... Can you please explain how did you do it?

@bradleyy1012
Copy link

hey everyone! i just solved this on my server! try using the absolute path to php!!
/usr/local/bin/php /path/to/artisan schedule:run >> /dev/null 2>&1

@javedLive
Copy link

You tried for Windows?

@taproot9
Copy link

taproot9 commented Mar 6, 2017

make a batch file

:loop
cd C:\xampp\htdocs\your_app
C:\xampp\php\php.exe artisan schedule:run 1>> NUL 2>&1
goto loop

and run it.

@ghost
Copy link

ghost commented May 4, 2017

@DarioCorno
My .bat file looks like this

cd c:\Users\User\Desktop\alerts
C:\wamp64\bin\php\php7.0.10\php.exe artisan schedule:run 1>> NUL 2>&1

The schedule function in the Kernel.php looks like this:

protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
$schedule->command('custome:command')->everyMinute();
}

And the actual task that will be called looks like this

public function handle()
{
echo 'Hello';
}

It doesn't give any output. I should automatically print "Hello" after a minute right?
But it doesn't.
Also just to confirm this output will be shown in the cmd prompt under my laravel project directory right?

@yusufbakkali12
Copy link

2024 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests