Skip to content

Conversation

uwascan
Copy link

@uwascan uwascan commented Mar 5, 2015

Changes made to src/Illuminate/Console/Scheduling/Event.php to support 'php artisan schedule:run > NUL 2>&1 &' on windows since '/dev/null' does not exist in windows environment.

…t php artisan schedule:run > NUL 2>&1 & on windows
@uwascan
Copy link
Author

uwascan commented Mar 5, 2015

php artisan schedule:run > /dev/null 2>&1 &
results in 'The system cannot find the path specified.' error on windows 7

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can turn this into a one-liner like this:

return strncasecmp(PHP_OS, 'WIN', 3) == 0;

@neomerx
Copy link

neomerx commented Mar 5, 2015

@neomerx
Copy link

neomerx commented Mar 5, 2015

@uwascan sudo for windows might look like $this->user ? 'runas /noprofile /user:'.$this->user.' '.$command : $command;

@neomerx
Copy link

neomerx commented Mar 5, 2015

@uwascan $this->output might need more attention
it's declared like

protected $output = '/dev/null';

and looks to be never changed.
It could be set correctly in constructor however it's needed to be considered that it's used in a couple of places like this

if (is_null($this->output) || $this->output == '/dev/null')
{
    ...
}

In such places it might require to change to something like

if (is_null($this->output) || $this->isOutputToNull())
{
    ...
}

with platform dependent implementation

@neomerx
Copy link

neomerx commented Mar 5, 2015

@uwascan You're one of the few lucky windows users :) as it requires more that just a couple of lines I would suggest asking @taylorotwell or/and @GrahamCampbell if they accept such changes.
Would be frustrating if they reject supporting it when all is done.

@ghost
Copy link

ghost commented Mar 5, 2015

To add to the above you need to use tabs, not spaces.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this file from your PR.

@GrahamCampbell
Copy link
Collaborator

Please fix the total cs mess.

@uwascan
Copy link
Author

uwascan commented Mar 7, 2015

Thank you all for your contributions. I realize now that I need to follow Laravel coding standards next time. I will clean up the code and try again. That was my first PR ever, imagine the excitement.
Laravel for Life!!!

@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 (with a windows based cron service [http://www.intelliadmin.com/index.php/2011/11/cron-service-for-windows/]) and all is good so far. I think this should be added to the docs.

@barryvdh
Copy link
Contributor

barryvdh commented Mar 7, 2015

Or use Symfony Process with disableOutput()? http://symfony.com/doc/current/components/process.html#disabling-output
Or look at how they do it perhaps.

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

Successfully merging this pull request may close these issues.

6 participants