在 PHP 中整齐地显示命令提示符的输出

我希望在命令提示符中运行一些命令后,整齐地显示 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:忽略2个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

我将不胜感激任何帮助或想法。谢谢。


海绵宝宝撒
浏览 132回答 2
2回答

慕田峪4524236

使用您的代码,您可以将换行符替换为<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>";

qq_遁去的一_1

您可以在 python 代码中执行以下操作。定义一个变量来保存类似x="<br>"然后用于输出,print(i+x)这将连接您的字符串。
打开App,查看更多内容
随时随地看视频慕课网APP