cmbYouku_Api/app/util/sm/Exec.php

48 lines
1.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\util\sm;
class Exec
{
protected static function dirPath(): string
{
return dirname(__FILE__) . DIRECTORY_SEPARATOR;
}
public static function exec(string $cmd): string
{
$output = null;
$returnVal = null;
$result = exec($cmd, $output, $returnVal);
if (0 !== $returnVal) {
throw new \LogicException('exec执行异常' . $cmd);
}
if (!$result) {
throw new \LogicException('exec执行返回值异常' . $cmd);
}
return trim($result);
}
public static function exec2(string $cmd)
{
$output = null;
$returnVal = null;
exec($cmd, $output, $returnVal);
if (0 !== $returnVal) {
throw new \LogicException('exec执行异常' . $cmd);
}
if (is_array($output)) {
if (count($output) == 2 && $output[1] !== 'success') {
throw new \LogicException($output[1]);
}
return $output[0];
}
return $output;
}
}