PHP + Shell返回HTML

我目前有一个问题,我试图执行shell脚本解释文件和回声的HTML,shell脚本执行完美本地但是当我尝试通过PHP执行它不会返回任何东西,似乎是通过PHP根本没有执行它,我有一个文件,这是执行脚本时,不会显示与PHP执行时创build的。 我有其他脚本与PHP执行完全正常,我有适当的万维网数据权限来执行此文件。 请帮助我,这是我正在执行的脚本和执行它的PHP文件。

<!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <table width="1000" border="0" align="center" cellpadding="0" cellspacing="0"> <tbody> <tr> <th style="font-size: 24px" scope="col"><p align="left" class="title_Font">Magnum Dongs <span style="font-size: 18px">&nbsp;|&nbsp; Mighty Meat Sticks 4 Kidz</span></p></th> </tr> </tbody> </table> <ul align="center" width="1000" height="50"> <li><a href="#home">Home</a></li> <li><a href="#news">Stories</a></li> <li><a href="#contact">Memes</a></li> <li><a href="#about">Shop</a></li> <li><a href="#email">Email</a></li> </ul> <table width="1000" height="386" border="0" align="center" cellpadding="0" cellspacing="0" class="body_Main"> <tbody> <?php echo exec('./var/www/html/newdongs/fetch_html.sh'); ?> </tbody> </table> </body> </html> 

 #!/usr/bin/env bash python3 /bin/dongs/db_Read.py >> lines #1 echo "<tr>" echo "<th scope='col'>" echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" echo "<tbody>" echo "<tr>" echo "<th scope='col' width='50'>" echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==11' lines`"</p>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==41' lines`"</p>" echo "<img src='"`awk 'NR==31' lines`"' width='150' height='150' alt=''/>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" echo "</th>" echo "<th scope='col' align='left' valign='top'>" echo "<p class='post' style='font-size: 14px'>"`awk 'NR==21' lines`"</p>" echo "</tr>" echo "</tbody>" echo "</table></th>" #2 echo "<tr>" echo "<th scope='col'>" echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" echo "<tbody>" echo "<tr>" echo "<th scope='col' width='50'>" echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==12' lines`"</p>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==42' lines`"</p>" echo "<img src='"`awk 'NR==32' lines`"' width='150' height='150' alt=''/>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" echo "</th>" echo "<th scope='col' align='left' valign='top'>" echo "<p class='post' style='font-size: 14px'>"`awk 'NR==22' lines`"</p>" echo "</tr>" echo "</tbody>" echo "</table></th>" #3 echo "<tr>" echo "<th scope='col'>" echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" echo "<tbody>" echo "<tr>" echo "<th scope='col' width='50'>" echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==13' lines`"</p>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==43' lines`"</p>" echo "<img src='"`awk 'NR==33' lines`"' width='150' height='150' alt=''/>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" echo "</th>" echo "<th scope='col' align='left' valign='top'>" echo "<p class='post' style='font-size: 14px'>"`awk 'NR==23' lines`"</p>" echo "</tr>" echo "</tbody>" echo "</table></th>" #4 echo "<tr>" echo "<th scope='col'>" echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" echo "<tbody>" echo "<tr>" echo "<th scope='col' width='50'>" echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==14' lines`"</p>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==44' lines`"</p>" echo "<img src='"`awk 'NR==34' lines`"' width='150' height='150' alt=''/>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" echo "</th>" echo "<th scope='col' align='left' valign='top'>" echo "<p class='post' style='font-size: 14px'>"`awk 'NR==24' lines`"</p>" echo "</tr>" echo "</tbody>" echo "</table></th>" #5 echo "<tr>" echo "<th scope='col'>" echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" echo "<tbody>" echo "<tr>" echo "<th scope='col' width='50'>" echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==15' lines`"</p>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==45' lines`"</p>" echo "<img src='"`awk 'NR==35' lines`"' width='150' height='150' alt=''/>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" echo "</th>" echo "<th scope='col' align='left' valign='top'>" echo "<p class='post' style='font-size: 14px'>"`awk 'NR==25' lines`"</p>" echo "</tr>" echo "</tbody>" echo "</table></th>" #6 echo "<tr>" echo "<th scope='col'>" echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" echo "<tbody>" echo "<tr>" echo "<th scope='col' width='50'>" echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==16' lines`"</p>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==46' lines`"</p>" echo "<img src='"`awk 'NR==36' lines`"' width='150' height='150' alt=''/>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" echo "</th>" echo "<th scope='col' align='left' valign='top'>" echo "<p class='post' style='font-size: 14px'>"`awk 'NR==26' lines`"</p>" echo "</tr>" echo "</tbody>" echo "</table></th>" #7 echo "<tr>" echo "<th scope='col'>" echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" echo "<tbody>" echo "<tr>" echo "<th scope='col' width='50'>" echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==17' lines`"</p>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==47' lines`"</p>" echo "<img src='"`awk 'NR==37' lines`"' width='150' height='150' alt=''/>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" echo "</th>" echo "<th scope='col' align='left' valign='top'>" echo "<p class='post' style='font-size: 14px'>"`awk 'NR==27' lines`"</p>" echo "</tr>" echo "</tbody>" echo "</table></th>" #8 echo "<tr>" echo "<th scope='col'>" echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" echo "<tbody>" echo "<tr>" echo "<th scope='col' width='50'>" echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==18' lines`"</p>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==48' lines`"</p>" echo "<img src='"`awk 'NR==38' lines`"' width='150' height='150' alt=''/>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" echo "</th>" echo "<th scope='col' align='left' valign='top'>" echo "<p class='post' style='font-size: 14px'>"`awk 'NR==28' lines`"</p>" echo "</tr>" echo "</tbody>" echo "</table></th>" #9 echo "<tr>" echo "<th scope='col'>" echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" echo "<tbody>" echo "<tr>" echo "<th scope='col' width='50'>" echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==19' lines`"</p>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==49' lines`"</p>" echo "<img src='"`awk 'NR==39' lines`"' width='150' height='150' alt=''/>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" echo "</th>" echo "<th scope='col' align='left' valign='top'>" echo "<p class='post' style='font-size: 14px'>"`awk 'NR==29' lines`"</p>" echo "</tr>" echo "</tbody>" echo "</table></th>" #10 echo "<tr>" echo "<th scope='col'>" echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>" echo "<tbody>" echo "<tr>" echo "<th scope='col' width='50'>" echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==20' lines`"</p>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==50' lines`"</p>" echo "<img src='"`awk 'NR==40' lines`"' width='150' height='150' alt=''/>" echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>" echo "</th>" echo "<th scope='col' align='left' valign='top'>" echo "<p class='post' style='font-size: 14px'>"`awk 'NR==30' lines`"</p>" echo "</tr>" echo "</tbody>" echo "</table></th>" 

我在这里先向您的帮助表示感谢!

我认为问题是PHP在错误的位置寻找脚本。

您可以使用getcwd()获取当前的工作目录。 检查您是否正在使用从当前工作目录到脚本的正确相对路径。

否则,您可以简单地将脚本的绝对路径传递给exec()命令。

接下来的问题是你的shell脚本打印了很多行,并以</table></th>exec()函数只返回shell脚本输出的最后一行。 所以PHP输出将只显示</table></th> 。 这不能在HTML中呈现,因为它们只是结束标记。 因此,您在浏览器中看不到任何更改,但是如果您检查HTML,则可以注意到它。

相反,您可以使用shell_exec()来返回shell脚本的整个输出。

这里是正确的版本:

 <?php // 1.Remove the leading dot. The leading dot makes the path relative. // 2.Use shell_exec instead to get all lines from your script output. echo shell_exec('/var/www/html/newdongs/fetch_html.sh'); ?>