[英]Executing Code in Python Web
im creating a webpage that will show me the SSID's available in my Network 即时通讯创建的网页将向我显示网络中可用的SSID
For this I have use this code: 为此,我使用以下代码:
nm-tool | nm-tool | grep "Infra" |
grep“ Infra” | cut -d " " -f5 > /home/nunukene/SSID3.txt
剪切-d“” -f5> /home/nunukene/SSID3.txt
Im saving this into a file called SSID3, to later open it using the open() , read() and str.split 我将其保存到名为SSID3的文件中,以便稍后使用open(),read()和str.split打开它
My problem is that the code I want to execute in the page, wont get executed, the file SSID3.txt wont be created 我的问题是我要在页面中执行的代码不会被执行,不会创建文件SSID3.txt
This is my website code so far: 到目前为止,这是我的网站代码:
#!/usr/bin/python
import os
import subprocess
import cgitb
cgitb.enable()
a=os.system("""nm-tool | grep "Infra" | cut -d " " -f5 > /home/nunukene/SSID3.txt""")
#SSIDStr = subprocess.check_output('nm-tool | grep "Infra" | cut -d " " -f5-6', shell=True)
#SSIDArray = str.split(SSIDStr)
ID = subprocess.check_output('ls', shell=True)
a='devilman'
print "Content-type:text/html\r\n\r\n"
print "<!DOCTYPE html>"
print "<html>"
print "<title> Not Hacking lol</title>"
print "<body>"
print "<h1> Join %s One of this networks <h1>" %(a)
print "</body>"
print "</html>"
I dont know how to get this process working before the rest! 我不知道如何在剩下的时间里使这个过程正常进行!
a reason your subprocess call didn't work is you would need to make a list out of all of the arguments to the command. 您的子流程调用无效的原因是您需要从命令的所有参数中列出一个清单。
SSIDStr = subprocess.check_output(['nm-tool','|','grep','"Infra"','|','cut','-d','" "','-f5']) SSIDStr = subprocess.check_output(['nm-tool','|','grep','“ Infra”','|','cut','-d','“”,'-f5'] )
(I'm not sure if you have to escape the double-quotes in this string) (我不确定您是否必须转义此字符串中的双引号)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.