Reputation: 649
I'm trying to concatenate the grater then caracter ">" to a string
I'm using the code but the output looks different as i want,
<?php
$target_file="home.txt"
$caract = htmlspecialchars(">");
$command = escapeshellcmd('sudo python test.py '.$target_file.$caract.' out.txt');
$output = shell_exec($command);
echo $command;
?>
also i tried the ">" but it gives the same results
here is the output of echo $command; how it is:
sudo python test.py home.txt \>\; out.txt
and i want it like that :
sudo python test.py home.txt > out.txt
Upvotes: 0
Views: 142
Reputation: 372
Don't use htmlspecialchars()
as shell_exec
does not understand HTML.
You should just use the code provided by @ArtisticPhoenix: shell_exec('sudo python test.py '.escapeshellarg( $target_file ).' > out.txt');
Hope this helps!
Upvotes: 1
Reputation: 7504
Usually you should call escapeshellcmd if you use user's input as part of the executing command. If you don't do you should simply call shell_exec(command);
shell_exec('sudo python test.py ' . $target_file . ' > out.txt');
Upvotes: 1