【发布时间】:2020-06-07 20:18:27
【问题描述】:
我是 Python/树莓派的新手。我正在尝试将finger 命令的所有行写入我的网络服务器。我的代码是这样编写的,它只返回第二行。
请参阅下面的代码:
import sys
import os
import time
import datetime
import pytz
import subprocess
then=datetime.datetime.now(pytz.utc)
TempString=str(then.astimezone(pytz.timezone('US/Eastern')))
TempString=TempString+"</br>"
print("The following is the result of the Terminal
Command
$finger…")
p=subprocess.Popen("finger", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
print(line)
TempStringF=line
retval=p.wait()
print("The following is the string stored in
TempStringF")
print(TempStringF)
print("Opening WWW Index File for Writing…")
file=open('/var/www/html/index.html','w')
file.write(TempString)
file.write(str(TempStringF))
file.close()
print("Index file has been updated and closed…")
【问题讨论】:
标签: python apache raspberry-pi