我希望在python文件在命令提示符中运行一些命令之后,整洁地显示它的输出。
目前,PHP代码的一部分如下所示:
$output2 = shell_exec('python amassprocess.py 2>&1' . $asnum);
echo $output2它基本上将用户输入发送到python文件amassprocess.py,并使用用户输入运行该文件。
amassprocess.py文件当前如下所示:
import os, sys
#asnum = sys.argv[1]
asnum = "46489"
print("Here is a list of top level seed domain related to the AS Number provided:")
topdomain = os.system('cmd /c "amass.exe intel -asn {}"'.format(asnum))
for i in topdomain:
print(i)
print("<br>")PS:忽略两个asnum,其中一个是用于测试的。
运行python脚本的结果如下:
Here is a list of top level seed domain related to the AS Number provided:
ttvnw.net
justin.tv
twitch.tv
socialcam.com
Traceback (most recent call last):
File "z:/xampp/htdocs/majorproject/amassprocess.py", line 8, in <module>
for i in topdomain:
TypeError: 'int' object is not iterable但是,我希望运行python脚本时的输出如下:
Here is a list of top level seed domain related to the AS Number provided:
ttvnw.net
<br>
justin.tv
<br>
twitch.tv
<br>
socialcam.com这样,当它在PHP中显示时,如下所示:
Here is a list of top level seed domain related to the AS Number provided:
ttvnw.net
justin.tv
twitch.tv
socialcam.com目前在PHP中,结果只显示在一行中,如下所示:
ttvnw.net justin.tv twitch.tv twitchcon.com socialcam.com Traceback (most recent call last): File "amassprocess.py", line 7, in for i in topdomain: TypeError: 'int' object is not iterable如有任何帮助或想法,我将不胜感激。谢谢。
发布于 2020-08-13 16:42:54
使用代码,可以用<br />替换换行符。
$output2 = shell_exec('python amassprocess.py 2>&1' . $asnum);
echo nl2br($output2);或者您可以获得一个行数组并在<br />上连接::
exec('python amassprocess.py 2>&1' . $asnum, $output2);
echo implode('<br />', $output2);或者,使用您的代码,您可以在<pre>或<code>标记中显示哪些浏览器将使用换行符、选项卡等呈现预先格式化的格式:
$output2 = shell_exec('python amassprocess.py 2>&1' . $asnum);
echo "<pre>$output2</pre>";发布于 2020-08-13 16:26:25
您可以在您的python代码中执行以下操作。
与x="<br>"
print(i+x),这将连接您的字符串.https://stackoverflow.com/questions/63399281
复制相似问题