<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/install.windows.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'install.windows.commandline.php',
    1 => 'Running PHP on the command line on Windows systems',
    2 => 'Running PHP on the command line on Windows systems',
  ),
  'up' => 
  array (
    0 => 'install.windows.php',
    1 => 'Встановлення в системах Windows',
  ),
  'prev' => 
  array (
    0 => 'install.windows.building.php',
    1 => 'Збирання з початкового коду',
  ),
  'next' => 
  array (
    0 => 'install.cloud.php',
    1 => 'Встановлення на платформи Cloud Computing',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'install/windows/commandline.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="install.windows.commandline" class="sect1">
 <h2 class="title">Running PHP on the command line on Windows systems</h2>
 <p class="para">
  This section contains notes and hints specific to getting PHP running
  from the command line for Windows.
 </p>
 <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
  <p class="para">
   Read the <a href="install.windows.manual.php" class="link">manual
   installation steps</a> first!
  </p>
 </p></blockquote>
 <p class="para">
  Getting PHP to run from the command line can be performed without making
  any changes to Windows.
  <div class="example-contents screen">
<div class="cdata"><pre>
C:\php\php.exe -f &quot;C:\PHP Scripts\script.php&quot; -- -arg1 -arg2 -arg3
</pre></div>     
  </div>
 </p>

 <p class="para">
  But there are some easy steps that can be followed to make this simpler.
  Some of these steps should already have been taken, but are repeated here
  to be able to provide a complete step-by-step sequence.

  <ul class="itemizedlist">
   <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
    <p class="para">
     Both <var class="envar">PATH</var> and <var class="envar">PATHEXT</var> are important
     pre-existing system variables in Windows,
     and care should be taken to not overwrite either variable,
     only to add to them.
    </p>
   </p></blockquote>

   <li class="listitem">
    <p class="para">
     Append the location of the PHP executable (<var class="filename">php.exe</var>,
     <var class="filename">php-win.exe</var> or <var class="filename">php-cli.exe</var>
     depending upon the PHP version and display preferences) to the
     <var class="envar">PATH</var> environment variable. Read more about how to
     add the appropriate directory to <var class="envar">PATH</var> in the <a href="faq.installation.php#faq.installation.addtopath" class="link">corresponding FAQ entry</a>.
    </p>
   </li>

   <li class="listitem">
    <p class="para">
     Append the <code class="literal">.PHP</code> extension to the
     <var class="varname">PATHEXT</var> environment variable. This can be done
     at the same time as amending the <var class="envar">PATH</var> environment
     variable. Follow the same steps as described in the <a href="faq.installation.php#faq.installation.addtopath" class="link">FAQ</a> but amend the
     <var class="varname">PATHEXT</var> environment variable rather than the
     <var class="envar">PATH</var> environment variable.
     <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
      <p class="para">
       The position in which the <code class="literal">.PHP</code> is placed will
       determine which script or program is executed when there are matching
       filenames. For example, placing <code class="literal">.PHP</code> before
       <code class="literal">.BAT</code> will cause the script to run, rather than
       the batch file, if there is a batch file with the same name.
      </p>
     </p></blockquote>
    </p>
   </li>

   <li class="listitem">
    <p class="para">
     Associate the <code class="literal">.PHP</code> extension with a file type. This
     is done by running the following command:
     <div class="example-contents screen">
<div class="cdata"><pre>
assoc .php=phpfile
</pre></div>     
     </div>
    </p>
   </li>

   <li class="listitem">
    <p class="para">
     Associate the <code class="literal">phpfile</code> file type with the appropriate
     PHP executable. This is done by running the following command:
     <div class="example-contents screen">
<div class="cdata"><pre>
ftype phpfile=&quot;C:\php\php.exe&quot; -f &quot;%1&quot; -- %~2
</pre></div>     
     </div>
    </p>
   </li>

  </ul>
 </p>

 <p class="para">
  Following these steps will allow PHP scripts to be run from any directory
  without the need to type the PHP executable or the <code class="literal">.PHP</code>
  extension and all parameters will be supplied to the script for processing.
 </p>

 <p class="para">
  The example below details some of the registry changes that can be made manually.
  <div class="example" id="example-1">
   <p><strong>Приклад #1 Registry changes</strong></p>
   <div class="example-contents screen">
<div class="cdata"><pre>
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.php]
@=&quot;phpfile&quot;
&quot;Content Type&quot;=&quot;application/php&quot;

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile]
@=&quot;PHP Script&quot;
&quot;EditFlags&quot;=dword:00000000
&quot;BrowserFlags&quot;=dword:00000008
&quot;AlwaysShowExt&quot;=&quot;&quot;

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\DefaultIcon]
@=&quot;C:\\php\\php-win.exe,0&quot;

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\shell]
@=&quot;Open&quot;

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\shell\Open]
@=&quot;&amp;Open&quot;

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\shell\Open\command]
@=&quot;\&quot;C:\\php\\php.exe\&quot; -f \&quot;%1\&quot; -- %~2&quot;
</pre></div>
   </div>
  </div>
 </p>

 <p class="para">
  With these changes the same command can be written as:
  <div class="example-contents screen">
<div class="cdata"><pre>
&quot;C:\PHP Scripts\script&quot; -arg1 -arg2 -arg3
</pre></div>
  </div>
  or, if the <code class="literal">&quot;C:\PHP Scripts&quot;</code> directory is in the
  <var class="envar">PATH</var> environment variable:
  <div class="example-contents screen">
<div class="cdata"><pre>
script -arg1 -arg2 -arg3
</pre></div>
  </div>
 </p>

 <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
  <p class="para">
   There is a small problem when intending to use this technique to run
   PHP scripts as a command line filter, like the example below:
   <div class="example-contents screen">
<div class="cdata"><pre>
dir | &quot;C:\PHP Scripts\script&quot; -arg1 -arg2 -arg3
</pre></div>
   </div>
   or
   <div class="example-contents screen">
<div class="cdata"><pre>
dir | script -arg1 -arg2 -arg3
</pre></div>
   </div>
   The script may simply hang and nothing is output.
   To get this operational, another registry change needs to be made:
   <div class="example-contents screen">
<div class="cdata"><pre>
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer]
&quot;InheritConsoleHandles&quot;=dword:00000001
</pre></div>
   </div>
   Further information regarding this issue can be found in this <a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;321788" class="link external">&raquo;&nbsp;Microsoft
   Knowledgebase Article : 321788</a>.
   As of Windows 10, this setting seems to be reversed, making the default install of
   Windows 10 support inherited console handles automatically. This <a href="https://social.msdn.microsoft.com/Forums/en-US/f19d740d-21c8-4dc2-a9ab-d5c0527e932b/nasty-file-association-regression-bug-in-windows-10-console?forum=windowssdk" class="link external">&raquo;&nbsp;
   Microsoft forum post</a> provides the explanation.
  </p>
 </p></blockquote>
</div><?php manual_footer($setup); ?>