Hamdi Charef
Hamdi Charef

Reputation: 649

Can't print special character in php

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 "&gt" 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

Answers (2)

Connor Gurney
Connor Gurney

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

Andrej
Andrej

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

Related Questions