Maslosoft Cli Shared API
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
<?php
/**
* This software package is licensed under `AGPL, Commercial` license[s].
*
* @package maslosoft/cli-shared
* @license AGPL, Commercial
*
* @copyright Copyright (c) Peter Maselkowski <pmaselkowski@gmail.com>
*/
namespace Maslosoft\Cli\Shared;
/**
* Cmd
*
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
*/
class Cmd
{
/**
* Run shell command in background, without PHP waiting to finish it.
* @param string $command
*/
public static function background($command)
{
if (Os::isWindows())
{
pclose(popen("start /B " . $command, "r"));
}
else
{
self::run($command . " &");
}
}
public static function run($command, & $output = null)
{
$pipes = [];
$descriptorspec = [
2 => ["pipe", "w"]
];
$process = proc_open($command, $descriptorspec, $pipes);
if (is_resource($process))
{
$output = stream_get_contents($pipes[2]);
fclose($pipes[2]);
$return = proc_close($process);
}
return $return;
}
}
API documentation generated by ApiGen