Reputation: 409
I'm trying to run a bash script in php; also, i want to see the log of the bash script. So, my php file looks like something like this:
<?php
$message=shell_exec("/var/www/html/judge/uploads/MyScript.sh 2>&1");
print_r($message);
?>
"Myscript.sh" is this :
#!/bin/bash
printf "MyScript \nran \nsuccesfully"
And the output is:
MyScript ran successfully
But i want the output to be something like this:
MyScript
ran
successfully
What should i do?
Upvotes: 1
Views: 2156
Reputation: 74220
Posting as a community wiki; I don't want rep from this.
As per my comment:
If you view your HTML source, you will see the line breaks are indeed there. If you want to see them on different lines "on screen", you need to use either <br>
or nl2br()
.
Reference:
Upvotes: 1