reference/exec/functions/exec.xml
b412bbd26214f7281ac7dd858710e09952a275f2
...
...
@@ -10,10 +10,10 @@
10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
12
<methodsynopsis>
13
-
<type>string</type><methodname>exec</methodname>
13
+
<type class="union"><type>string</type><type>false</type></type><methodname>exec</methodname>
14
14
<methodparam><type>string</type><parameter>command</parameter></methodparam>
15
-
<methodparam choice="opt"><type>array</type><parameter role="reference">output</parameter></methodparam>
16
-
<methodparam choice="opt"><type>int</type><parameter role="reference">return_var</parameter></methodparam>
15
+
<methodparam choice="opt"><type>array</type><parameter role="reference">output</parameter><initializer>&null;</initializer></methodparam>
16
+
<methodparam choice="opt"><type>int</type><parameter role="reference">result_code</parameter><initializer>&null;</initializer></methodparam>
17
17
</methodsynopsis>
18
18
<para>
19
19
<function>exec</function> executes the given
...
...
@@ -49,10 +49,10 @@
49
49
</listitem>
50
50
</varlistentry>
51
51
<varlistentry>
52
-
<term><parameter>return_var</parameter></term>
52
+
<term><parameter>result_code</parameter></term>
53
53
<listitem>
54
54
<para>
55
-
If the <parameter>return_var</parameter> argument is present
55
+
If the <parameter>result_code</parameter> argument is present
56
56
along with the <parameter>output</parameter> argument, then the
57
57
return status of the executed command will be written to this
58
58
variable.
...
...
@@ -71,11 +71,50 @@
71
71
any interference, use the <function>passthru</function> function.
72
72
</para>
73
73
<para>
74
+
Returns &false; on failure.
75
+
</para>
76
+
<para>
74
77
To get the output of the executed command, be sure to set and use the
75
78
<parameter>output</parameter> parameter.
76
79
</para>
77
80
</refsect1>
78
81

82
+
<refsect1 role="errors">
83
+
&reftitle.errors;
84
+
<para>
85
+
Emits an <constant>E_WARNING</constant> if <function>exec</function>
86
+
is unable to execute the <parameter>command</parameter>.
87
+
</para>
88
+
<para>
89
+
Throws a <classname>ValueError</classname> if <parameter>command</parameter>
90
+
is empty or contains null bytes.
91
+
</para>
92
+
</refsect1>
93
+

94
+
<refsect1 role="changelog">
95
+
&reftitle.changelog;
96
+
<informaltable>
97
+
<tgroup cols="2">
98
+
<thead>
99
+
<row>
100
+
<entry>&Version;</entry>
101
+
<entry>&Description;</entry>
102
+
</row>
103
+
</thead>
104
+
<tbody>
105
+
<row>
106
+
<entry>8.0.0</entry>
107
+
<entry>
108
+
If <parameter>command</parameter> is empty or contains null bytes,
109
+
<function>exec</function> now throws a <classname>ValueError</classname>.
110
+
Previously it emitted an <constant>E_WARNING</constant> and returned &false;.
111
+
</entry>
112
+
</row>
113
+
</tbody>
114
+
</tgroup>
115
+
</informaltable>
116
+
</refsect1>
117
+

79
118
<refsect1 role="examples">
80
119
&reftitle.examples;
81
120
<para>
...
...
@@ -86,10 +125,24 @@
86
125
<?php
87
126
// outputs the username that owns the running php/httpd process
88
127
// (on a system with the "whoami" executable in the path)
89
-
echo exec('whoami');
128
+
$output=null;
129
+
$retval=null;
130
+
exec('whoami', $output, $retval);
131
+
echo "Returned with status $retval and output:\n";
132
+
print_r($output);
90
133
?>
91
134
]]>
92
135
</programlisting>
136
+
&example.outputs.similar;
137
+
<screen>
138
+
<![CDATA[
139
+
Returned with status 0 and output:
140
+
Array
141
+
(
142
+
[0] => cmb
143
+
)
144
+
]]>
145
+
</screen>
93
146
</example>
94
147
</para>
95
148
</refsect1>
...
...
@@ -114,7 +167,6 @@ echo exec('whoami');
114
167
</para>
115
168
</refsect1>
116
169
</refentry>
117
-

118
170
<!-- Keep this comment at the end of the file
119
171
Local variables:
120
172
mode: sgml
121
173