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

Default path/location of script #246

Closed
hhuy0001 opened this issue Sep 27, 2019 · 9 comments
Closed

Default path/location of script #246

hhuy0001 opened this issue Sep 27, 2019 · 9 comments

Comments

@hhuy0001
Copy link

Crunz version: 2.0

PHP version: 7.3.4

Operating system type and version: Windows 10 Enterprise 64-bit

Description
I'm confused about how to point my Task file to a script file.

How to reproduce
I have a NotificationTasks.php file located in the tasks folder, which is in the project root.

<?php

use Crunz\Schedule;

$schedule = new Schedule();
$task = $schedule->run('/usr/bin/php Notify.php');
$task
    ->daily()
    ->description('Remind admins and participants about programs and sections');
return $schedule;

Notify.php is also located in the same folder.

When I try to test this by running schedule:run --force, I receive a The system cannot find the path specified error.

I'm not sure, for example, in the documentation example, where backup.php should be located.
I have also tried messing around with the in() method without success.

@PabloKowalczyk
Copy link
Collaborator

Hello, it will be much better if you use absolute paths, like __DIR__ . '/Notify.php', in you example: $task = $schedule->run('/usr/bin/php' . __DIR__ . '/Notify.php');

Crunz run each task as a separate process which cwd is the same like current cwd - I'm 99% sure, if you want i could debug it to make 100% sure. Another thing is in() method, it should work and is created to solve cases like yours.
How you use in() method? Maybe there is some bug in in() method. IMO $task->in(__DIR__) should do the trick.

Maybe you have some ideas how documentation can be upgraded? I'm open for PR, feel free to open one, if you want.

To summarize: always use absolute paths 😃

@hhuy0001
Copy link
Author

Okay that makes sense.

However, using $task = $schedule->run('/usr/bin/php' . __DIR__ . '/Notify.php'); throws The filename, directory name, or volume label syntax is incorrect.

Alternatively, $task->in(__DIR__) throws The system cannot find the path specified.

I apologise if this is really basic, and I appreciate the help a lot!

@PabloKowalczyk
Copy link
Collaborator

Looks like you forget space after php binary, should be: run('/usr/bin/php ' . __DIR__ . '/Notify.php').

@hhuy0001
Copy link
Author

That still throws The system cannot find the path specified.

@PabloKowalczyk
Copy link
Collaborator

Could you create reproducer repository?

@hhuy0001
Copy link
Author

Sorry I'm not sure how to best create a repro. Here is a screenshot of the file structure of my project though.
phpstorm64_2019-09-28_21-22-54

@PabloKowalczyk
Copy link
Collaborator

So, I forget about one important thing - you are using Windows, so your PHP binary is definitely not /usr/php/bin :) Try this command: PHP_BINARY . ' ' . __DIR__ . DIRECTORY_SEPARATOR . 'Notify.php'.

@hhuy0001
Copy link
Author

Yes, that worked. Thank you for your help!

@PabloKowalczyk
Copy link
Collaborator

#256 was merged to suggest using PHP_BINARY, thanks @hhuy0001.

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

2 participants