I am trying to run this javascript below but am not seeing the output of the php shell_exec command.
Running the test -a bash script will output a series of ID's 34535, 25643, 23262, and so on. When I run it in my php file with a simple it works fine.
print shell_exec('/opt/bin/echkchunk -a');
But when I try to run it below and I select test1 there is nothing outputted to the screen. Looking through chromes developer tools I see the code when test1 is selected as the following
<!--?php shell_exec("/opt/bin/echkchunk -a"); ?-->
as if it is commented out.
So my question is, is it possible to run the bash script this way with php and JavaScript? Or is there another way to get that information displayed to the webpage without JavaScript?
<script type="text/javascript">
var tester = '<?php shell_exec("/opt/bin/test -a"); ?>';
$(document).ready(function() {
$("#selector").on("change", function() {
if ($("#selector").val() == "test1") {
$("#rightselection").css("background-color", "red");
$("#rightselection").html(tester);
}
if ($("#selector").val() == "test2") {
$("#rightselection").css("background-color", "blue");
$("#rightselection").html("test2");
}
if ($("#selector").val() == "test3"){
$("#rightselection").css("background-color", "yellow");
$("#rightselection").html("test3");
}
if ($("#selector").val() == ""){
$("#rightselection").css("background-color", "green");
$("#rightselection").html("This is a Test");
}
});
});
</script>
If your result is multi line, you need to replace the newline marker with escape sequence or HTML. Try to replace
var tester = '<?php shell_exec("/opt/bin/test -a"); ?>';
with
var tester = '<?php echo str_replace(PHP_EOL, '<br/>', shell_exec("/opt/bin/test -a")); ?>';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With