Answers.Body: <p>It looks like you are using an incorrect version of php when this command runs from cron. According to <a href="https://www.drupal.org/project/drush/issues/1961862" rel="nofollow noreferrer">this resource</a> you are receiving these errors because you are using php-cgi rather than the php CLI binary. Most reports of this error are regarding 1 &amp; 1 hosting.</p>
  
  <p>Rather than using /usr/bin/drush use something like this:</p>
  
  <blockquote>
    <p>/usr/bin/php /usr/local/bin/drush {rest of the command}</p>
  </blockquote>
  
  <p>Where /usr/bin/php is the path to the php CLI binary on your system. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-13T17:47:31.387Z
Answers.LastActivityDate: 2018-07-13T17:47:31.387Z
Answers.UserDisplayName: lolcode
Answers.Body: <p>Add this line to the crontab file:</p>
  
  <pre><code>PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-13T12:56:56.477Z
Answers.Text: Thanks for contributing.  It helps if you explain why you are recommending something and how it helps solve the issue.  Since the command in cron is using absolute paths, it is not obvious why setting the path variable will make any difference.
Answers.UserDisplayName: Aidan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-13T11:43:53.193Z
Answers.LastActivityDate: 2018-07-13T11:43:53.193Z
Answers.UserDisplayName: Plazik
Body: <p>I have the command in cron  <code>cd /home/quabbinm/ &amp;&amp; /usr/local/bin/drush -r /home/quabbinm/public_html/trainingactivebystanders.org -l https://trainingactivebystanders.org -u nan civicrm-api job.execute</code>
  which results in errors </p>
  
  <pre><code>X-Powered-By: PHP/5.6.33
  Content-type: text/html; charset=UTF-8
  
  &lt;br /&gt;
  &lt;b&gt;Notice&lt;/b&gt;:  Undefined variable: argv in &lt;b&gt;phar:///usr/local/bin/drush/drush&lt;/b&gt; on line &lt;b&gt;114&lt;/b&gt;&lt;br /&gt;
  &lt;br /&gt;
  &lt;b&gt;Warning&lt;/b&gt;:  array_shift() expects parameter 1 to be array, null given in &lt;b&gt;phar:///usr/local/bin/drush/includes/startup.inc&lt;/b&gt; on line &lt;b&gt;171&lt;/b&gt;&lt;br /&gt;
  &lt;br /&gt;
  &lt;b&gt;Warning&lt;/b&gt;:  Invalid argument supplied for foreach() in &lt;b&gt;phar:///usr/local/bin/drush/includes/startup.inc&lt;/b&gt; on line &lt;b&gt;182&lt;/b&gt;&lt;br /&gt;
  &lt;br /&gt;
  &lt;b&gt;Warning&lt;/b&gt;:  pcntl_exec() expects parameter 2 to be array, null given in &lt;b&gt;phar:///usr/local/bin/drush/includes/startup.inc&lt;/b&gt; on line &lt;b&gt;359&lt;/b&gt;&lt;br /&gt;
  &lt;br /&gt;
  &lt;b&gt;Notice&lt;/b&gt;:  Use of undefined constant STDERR - assumed 'STDERR' in &lt;b&gt;phar:///usr/local/bin/drush/includes/startup.inc&lt;/b&gt; on line &lt;b&gt;363&lt;/b&gt;&lt;br /&gt;
  &lt;br /&gt;
  &lt;b&gt;Warning&lt;/b&gt;:  fwrite() expects parameter 1 to be resource, string given in &lt;b&gt;phar:///usr/local/bin/drush/includes/startup.inc&lt;/b&gt; on line &lt;b&gt;363&lt;/b&gt;&lt;br /&gt;
  &lt;br /&gt;
  &lt;b&gt;Notice&lt;/b&gt;:  Use of undefined constant STDERR - assumed 'STDERR' in &lt;b&gt;phar:///usr/local/bin/drush/includes/startup.inc&lt;/b&gt; on line &lt;b&gt;364&lt;/b&gt;&lt;br /&gt;
  &lt;br /&gt;
  &lt;b&gt;Warning&lt;/b&gt;:  fwrite() expects parameter 1 to be resource, string given in &lt;b&gt;phar:///usr/local/bin/drush/includes/startup.inc&lt;/b&gt; on line &lt;b&gt;364&lt;/b&gt;&lt;br /&gt;
  </code></pre>
  
  <p>When I run the same command at the command line it runs fine</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-01-28T00:49:16.243Z
Comments.Text: two questions:
  if you run drush manually on the command line do you get the same errors?
  
  can you try to have your cron task cd into the site directory so you can run drush without having to give it the site parameters ?
Comments.UserDisplayName: ericG
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-01-29T14:50:48.053Z
Comments.Text: When I run this at the command line it runs fine. I am doing a cd into the site directory. What are you suggesting otherwise?
Comments.UserDisplayName: Nan Riebschlaeger
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-01-29T15:40:02.727Z
Comments.Text: I tried this cd /home/quabbinm/public_html/trainingactivebystanders.org && /usr/local/bin/drush -r https://trainingactivebystanders.org -u nan civicrm-api job.execute and get the message civicrm-api job.execute can't be found
Comments.UserDisplayName: Nan Riebschlaeger
Tags: <cron>
Title: How to get job.execute to run with drush
ThreadText: # How to get job.execute to run with drush
  
  (Asked by: username_0 on 2018-01-27)
  
  I have the command in cron  cd /home/quabbinm/ && /usr/local/bin/drush -r /home/quabbinm/public_html/trainingactivebystanders.org -l https://trainingactivebystanders.org -u nan civicrm-api job.execute
  which results in errors 
  X-Powered-By: PHP/5.6.33
  Content-type: text/html; charset=UTF-8
  
  
  Notice:  Undefined variable: argv in phar:///usr/local/bin/drush/drush on line 114
  
  Warning:  array_shift() expects parameter 1 to be array, null given in phar:///usr/local/bin/drush/includes/startup.inc on line 171
  
  Warning:  Invalid argument supplied for foreach() in phar:///usr/local/bin/drush/includes/startup.inc on line 182
  
  Warning:  pcntl_exec() expects parameter 2 to be array, null given in phar:///usr/local/bin/drush/includes/startup.inc on line 359
  
  Notice:  Use of undefined constant STDERR - assumed 'STDERR' in phar:///usr/local/bin/drush/includes/startup.inc on line 363
  
  Warning:  fwrite() expects parameter 1 to be resource, string given in phar:///usr/local/bin/drush/includes/startup.inc on line 363
  
  Notice:  Use of undefined constant STDERR - assumed 'STDERR' in phar:///usr/local/bin/drush/includes/startup.inc on line 364
  
  Warning:  fwrite() expects parameter 1 to be resource, string given in phar:///usr/local/bin/drush/includes/startup.inc on line 364
  
  When I run the same command at the command line it runs fine
  
  **Tags:** cron
  
  > **Comments:**
  > **username_1**: two questions: if you run drush manually on the command line do you get the same errors?  can you try to have your cron task cd into the site directory so you can run drush without having to give it the site parameters ?  
  > **username_0**: When I run this at the command line it runs fine. I am doing a cd into the site directory. What are you suggesting otherwise?  
  > **username_0**: I tried this cd /home/quabbinm/public_html/trainingactivebystanders.org && /usr/local/bin/drush -r https://trainingactivebystanders.org -u nan civicrm-api job.execute and get the message civicrm-api job.execute can't be found  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2018-07-13. Score: 1
  
  It looks like you are using an incorrect version of php when this command runs from cron. According to [this resource](https://www.drupal.org/project/drush/issues/1961862) you are receiving these errors because you are using php-cgi rather than the php CLI binary. Most reports of this error are regarding 1 & 1 hosting.
  
  Rather than using /usr/bin/drush use something like this:
  
  > /usr/bin/php /usr/local/bin/drush {rest of the command}
  
  Where /usr/bin/php is the path to the php CLI binary on your system.
  
  
  ---
  
  ### Answer by username_3 on 2018-07-13. Score: -1
  
  Add this line to the crontab file:
  PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  
  > **Comments:**
  > **username_4**: Thanks for contributing.  It helps if you explain why you are recommending something and how it helps solve the issue.  Since the command in cron is using absolute paths, it is not obvious why setting the path variable will make any difference.  
  
  ---
  
  