laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.51k stars 11.01k forks source link

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

Closed uwascan closed 9 years ago

uwascan commented 9 years ago

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 commented 9 years ago

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

crynobone commented 9 years ago

http://superuser.com/a/777230

uwascan commented 9 years ago

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 commented 9 years ago

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

uwascan commented 9 years ago

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

neomerx commented 9 years ago

@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 commented 9 years ago

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

crynobone commented 9 years ago

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 commented 9 years ago

@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 commented 9 years ago

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

neomerx commented 9 years ago

@uwascan FYI one of the 'windows as a PHP server' sad stories

uwascan commented 9 years ago

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

uwascan commented 9 years ago

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 commented 9 years ago

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

dnetix commented 9 years ago

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 commented 9 years ago

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

cvlug commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

@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 commented 8 years ago

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 commented 8 years ago

You tried for Windows?

taproot9 commented 7 years ago

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 commented 7 years ago

@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 commented 15 hours ago

2024 😂