File: commandline.xml

package info (click to toggle)
php-doc 20100521-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 59,992 kB
  • ctags: 4,085
  • sloc: xml: 796,833; php: 21,338; cpp: 500; sh: 117; makefile: 58; awk: 28
file content (197 lines) | stat: -rw-r--r-- 5,989 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Revision: 295232 $ -->
   <sect1 xml:id="install.windows.commandline" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
    <title>Command Line PHP on Microsoft Windows</title>
    <para>
     This section contains notes and hints specific to getting PHP running
     from the command line for Windows.
    </para>
    <note>
     <para>
      You should read the <link linkend="install.windows.manual">manual
      installation steps</link> first!
     </para>
    </note>
    <para>
     Getting PHP to run from the command line can be performed without making
     any changes to Windows.
     <screen>
<![CDATA[
C:\PHP5\php.exe -f "C:\PHP Scripts\script.php" -- -arg1 -arg2 -arg3
]]>     
     </screen>
    </para>

    <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.
     <itemizedlist>

      <listitem>
       <para>
        Add the location of the PHP executable (<filename>php.exe</filename>,
        <filename>php-win.exe</filename> or <filename>php-cli.exe</filename>
        depending upon your PHP version and display preferences) to the
        <varname>PATH</varname> environment variable. Read more about how to
        add your PHP directory to <varname>PATH</varname> in the <link
        linkend="faq.installation.addtopath">corresponding FAQ entry</link>.
       </para>
      </listitem>

      <listitem>
       <para>
        Add the <literal>.PHP</literal> extension to the
        <varname>PATHEXT</varname> environment variable. This can be done
        at the same time as amending the <varname>PATH</varname> environment
        variable. Follow the same steps as described in the <link
        linkend="faq.installation.addtopath">FAQ</link> but amend the
        <varname>PATHEXT</varname> environment variable rather than the
        <varname>PATH</varname> environment variable.
        <note>
         <para>
          The position in which you place the <literal>.PHP</literal> will
          determine which script or program is executed when there are matching
          filenames. For example, placing <literal>.PHP</literal> before
          <literal>.BAT</literal> will cause your script to run, rather than
          the batch file, if there is a batch file with the same name.
         </para>
        </note>
       </para>
      </listitem>

      <listitem>
       <para>
        Associate the <literal>.PHP</literal> extension with a file type. This
        is done by running the following command:
        <screen>
<![CDATA[
assoc .php=phpfile
]]>     
        </screen>
       </para>
      </listitem>

      <listitem>
       <para>
        Associate the <literal>phpfile</literal> file type with the appropriate
        PHP executable. This is done by running the following command:
        <screen>
<![CDATA[
ftype phpfile="C:\PHP5\php.exe" -f "%1" -- %~2
]]>     
        </screen>
       </para>
      </listitem>

     </itemizedlist>
    </para>

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

    <para>
     The example below details some of the registry changes that can be made manually.
     <example>
      <title>Registry changes</title>
      <screen>
<![CDATA[
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.php]
@="phpfile"
"Content Type"="application/php"

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

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\DefaultIcon]
@="C:\\PHP5\\php-win.exe0"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\shell]
@="Open"

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

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\phpfile\shell\Open\command]
@="\"C:\\PHP5\\php.exe\" -f \"%1\" -- %~2"
]]>
      </screen>
     </example>
    </para>

    <para>
     With these changes the same command can be written as:
     <screen>
<![CDATA[
"C:\PHP Scripts\script" -arg1 -arg2 -arg3
]]>
     </screen>
     or, if your <literal>"C:\PHP Scripts"</literal> path is in the
     <literal>PATH</literal> environment variable:
     <screen>
<![CDATA[
script -arg1 -arg2 -arg3
]]>
     </screen>
    </para>

    <note>
     <para>
      There is a small problem if you intend to use this technique and use your
      PHP scripts as a command line filter, like the example below:
      <screen>
<![CDATA[
dir | "C:\PHP Scripts\script" -arg1 -arg2 -arg3
]]>
      </screen>
      or
      <screen>
<![CDATA[
dir | script -arg1 -arg2 -arg3
]]>
      </screen>
      You may find that the script simply hangs and nothing is output.
      To get this operational, you need to make another registry change.
      <screen>
<![CDATA[
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer]
"InheritConsoleHandles"=dword:00000001
]]>
      </screen>
      Further information regarding this issue can be found in this <link
      xlink:href="http://support.microsoft.com/default.aspx?scid=kb;en-us;321788">Microsoft
      Knowledgebase Article : 321788</link>.
     </para>
    </note>
   </sect1>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->