4
* Execute a command and capture stdout and stderr. If the command exits with
5
* a nonzero error code, a @{class:CommandException} will be thrown. If you need
6
* to manually handle error conditions, use @{function:exec_manual}.
8
* list ($stdout, $stderr) = execx('ls %s', $file);
10
* @param string sprintf()-style command pattern to execute.
11
* @param ... Arguments to sprintf pattern.
12
* @return array List of stdout and stderr.
14
function execx($cmd /* , ... */) {
15
$args = func_get_args();
16
$future = newv('ExecFuture', $args);
17
return $future->resolvex();
22
* Execute a command and capture stdout, stderr, and the return value.
24
* list ($err, $stdout, $stderr) = exec_manual('ls %s', $file);
26
* When invoking this function, you must manually handle the error condition.
27
* Error flows can often be simplified by using @{function:execx} instead,
28
* which throws an exception when it encounters an error.
30
* @param string sprintf()-style command pattern to execute.
31
* @param ... Arguments to sprintf pattern.
32
* @return array List of return code, stdout, and stderr.
34
function exec_manual($cmd /* , ... */) {
35
$args = func_get_args();
36
$ef = newv('ExecFuture', $args);
37
return $ef->resolve();
42
* Wrapper for @{class:PhutilExecPassthru}.
44
* @param string sprintf()-style command pattern to execute.
45
* @param ... Arguments to sprintf pattern.
46
* @return int Return code.
48
function phutil_passthru($cmd /* , ... */) {
49
$args = func_get_args();
50
return newv('PhutilExecPassthru', $args)->execute();
55
* Return a human-readable signal name (like "SIGINT" or "SIGKILL") for a given
58
* @param int Signal number.
59
* @return string Human-readable signal name.
61
function phutil_get_signal_name($signo) {
62
// These aren't always defined; try our best to look up the signal name.
63
$constant_names = array(
99
$signal_names = array();
100
foreach ($constant_names as $constant) {
101
if (defined($constant)) {
102
$signal_names[constant($constant)] = $constant;
106
return idx($signal_names, $signo);