Framework: php artisan schedule:run does not work in windows

Created on 4 Mar 2015  路  23Comments  路  Source: laravel/framework

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)PHPv5.6php.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.

Most helpful comment

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

All 23 comments

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

I commented out the part the method 'buildCommand' in IlluminateConsoleSchedulingEvent.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.

Is there any best practice on how to extend or replace IlluminateConsoleSchedulingEvent.php?

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

@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?

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

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.

@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.

@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 :+1:

The project I am working is used internally on a private LAN. I submitted a pull request a few hours ago. My very first. https://github.com/laravel/framework/pull/7887

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.

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

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.

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

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:phpsitestouristpreviewlaravelartisan 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:phpsitestouristpreviewlaravelvendorsymfonyconsoleInputArgvInput.php:177
Stack trace:

0 D:phpsitestouristpreviewlaravelvendorsymfonyconsoleInputArgvInput.php(86): SymfonyComponentConsoleInputArgvInput->parseArgument('>')

1 D:phpsitestouristpreviewlaravelvendorsymfonyconsoleInputInput.php(61): SymfonyComponentConsoleInputArgvInput->parse()

2 D:phpsitestouristpreviewlaravelvendorsymfonyconsoleCommandCommand.php(221): SymfonyComponentConsoleInputInput->bind(Object(SymfonyComponentConsoleInputInputDefinition))

3 D:phpsitestouristpreviewlaravelvendorlaravelframeworksrcIlluminateConsoleCommand.php(136): SymfonyComponentConsoleCommandCommand->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))

4 D:phpsitestouristpreviewlaravelvendorsymfonyconsoleApplication.php(838): IlluminateConsoleCommand->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))

5 D:phpsitestouristpreviewlaravelvendorsymfonyconsoleApplication.php(189): SymfonyComponentConsoleApplication->doRunCommand(Object(IlluminateConsoleSchedulingScheduleRunCommand), Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))

6 D:phpsitestouristpreviewlaravelvendorsymfonyconsoleApplication.php(120): SymfonyComponentConsoleApplication->doRun(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))

7 D:phpsitestouristpreviewlaravelvendorlaravelframeworksrcIlluminateFoundationConsoleKernel.php(107): SymfonyComponentConsoleApplication->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))

8 D:phpsitestouristpreviewlaravelartisan(36): IlluminateFoundationConsoleKernel->handle(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))

9 {main}

Anybody please have a solution?

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

@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?

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

You tried for Windows?

make a batch file

:loop
cd C:xampphtdocsyour_app
C:xamppphpphp.exe artisan schedule:run 1>> NUL 2>&1

goto loop

and run it.

@DarioCorno
My .bat file looks like this

cd c:UsersUserDesktopalerts
C:wamp64binphpphp7.0.10php.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?

Was this page helpful?
0 / 5 - 0 ratings