web-console icon indicating copy to clipboard operation
web-console copied to clipboard

Alias not working

Open celorodovalho opened this issue 8 years ago • 1 comments

I have a hostgator shared account. In my .bashrc i have:

alias php='/opt/php71/bin/php'
alias composer='/home/XXX/bin/composer.phar'

In webconsole, when I try to run:

php -v

I got:

Content-Type: application/json
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: x-requested-with, content-type

{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error","data":null}}

or when I try to run:

composer -v

I got:

sh: composer: command not found

celorodovalho avatar Dec 15 '17 15:12 celorodovalho

I must to do that in function "execute_command":

// Command execution
function execute_command($command) {
    $descriptors = array(
        0 => array('pipe', 'r'), // STDIN
        1 => array('pipe', 'w'), // STDOUT
        2 => array('pipe', 'w')  // STDERR
    );
	$preCommand = [
		'export HOME=/home/XXX'
	];
	$commands = [
		'php' => '/opt/php71/bin/php',
		'composer.phar' => '/opt/php71/bin/php /home/XXX/bin/composer.phar',
		'composer' => '/opt/php71/bin/php /home/XXX/bin/composer.phar',
	];
	foreach ($commands as $key => $cmd) {
		$command = preg_replace('/(^|\s)('.$key.')($|\s)/i', '$1'.$cmd.'$3', $command);
	}
	$preCommand = implode(' && ', $preCommand).' && ';

    $process = proc_open($preCommand.$command . ' 2>&1', $descriptors, $pipes);
    if (!is_resource($process)) die("Can't execute command.");

    // Nothing to push to STDIN
    fclose($pipes[0]);

    $output = stream_get_contents($pipes[1]);
    fclose($pipes[1]);

    $error = stream_get_contents($pipes[2]);
    fclose($pipes[2]);

    // All pipes must be closed before "proc_close"
    $code = proc_close($process);

    return $output;
}

celorodovalho avatar Dec 15 '17 17:12 celorodovalho