I am a complete beginner in PHP.
I want to execute a java .jar file using PHP.The jar file takes input from STDIN
and generates the output at STDOUT
.To execute the jar file this is what I do in my Ubuntu Linux terminal:
./java/bin/java -jar abc.jar <here goes the STDIN> Ctrl+D <The output gets generated here at the STDOUT>
This works perfect.However when I replicate this in PHP as:
$p=shell_exec("./java/bin/java -jar abc.jar $s 0<&-");
This sends $p
the output generated when STDIN
is empty.Which definitely means that $s
is not being passed.I am perfectly sure my jar file works perfectly,it’s the php script where my mistake is.Can anyone please point out my mistake? Thanks in advance.
Advertisement
Answer
Complete shot in the dark, but:
$p=shell_exec(sprintf('./java/bin/java -jar abc.jar "%s" 0<&-', addslashes($s)));
It could be a case that $s
contains unescaped characters that ruin the command syntax.