shell exec - PHP shell_exec() doesn't allow less-than "<" character or "<()" command to be used?
Get the solution ↓↓↓I need to run this exact shell command from PHP shell_exec():
/usr/bin/paste -d'|' <(echo $(id)) <(echo $(pwd))
From a VPS shell (Debian) it works perfectly. However, from shell_exec() it doesn't work:
$command = "/usr/bin/paste -d'|' <(echo $(id)) <(echo $(pwd)) 2>&1";
$output = shell_exec($command);
print_r($output);
It doesn't output anything, the output is just blank/empty.
I am using PHP 7.3 with safe_mode = On and open_basedir, shell_exec() is enabled.
How can I run that command with shell_exec()?
I think the less-than "<" char or "<()" create problems?
Answer
Solution:
perhaps escapeshellcmd would help ?
$command = "/usr/bin/paste -d'|' <(echo $(id)) <(echo $(pwd)) 2>&1";
$escaped_command = escapeshellcmd($command);
$output = shell_exec($escaped_command);
print_r($output);
good luck.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: installation failed, reverting ./composer.json and ./composer.lock to their original content.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.