php中不能打印特殊字符


Can't print special character in php

我试图将较大的字符">"连接到字符串

我正在使用代码,但输出看起来与我想要的不同,

<?php
$target_file="home.txt"
$caract = htmlspecialchars(">");
$command = escapeshellcmd('sudo python test.py '.$target_file.$caract.' out.txt');
$output = shell_exec($command);
echo $command;
?>

我也尝试了">,但它给出了相同的结果

这里是echo $command的输出;情况:

sudo python test.py home.txt '>'; out.txt

我想要这样:

sudo python test.py home.txt > out.txt

如果使用用户输入作为执行命令的一部分,通常应该调用escapeshellcmd。如果您不这样做,您应该简单地调用shell_exec(command);

shell_exec('sudo python test.py ' . $target_file . ' > out.txt');

不要使用htmlspecialchars(),因为shell_exec不理解HTML。

你应该使用@ artiticphoenix: shell_exec('sudo python test.py '.escapeshellarg( $target_file ).' > out.txt');提供的代码,希望这有助于!