从后台启动的 python 程序打印消息
print message from python program that started in background
我制作了一个 python 程序,当我连接到 ppp network.The 应用程序请求 www.noip.com 到 link 我创建的主机的任何新 IP他们的网站。
/etc/ppp/ip-up.d/noip.sh #this script calls my python app
当我连接到 ppp 时,脚本 运行 正常,python 应用程序被触发并确实更改了我在 www.noip.com 上的 IP 地址,但我无法打印仅使用 print
向控制台发送消息。我的应用程序中有一些 print
语句,只有当我从命令行 运行 应用程序时才有效,例如 ./myapp.py
如果我的 python 应用程序是从后台调用的,如何显示消息?
这是我的 Python 代码:
#!/usr/bin/python
import requests
import netifaces as ni
user = 'xxxxxxx'
pswd = 'xxxxxxx'
ni.ifaddresses('ppp0')
ip = ni.ifaddresses('ppp0')[2][0]['addr']
myhostname = 'xxxxxxx'
payload = {'hostname' : myhostname , 'myip' : ip}
r = requests.get("http://dynupdate.no-ip.com/nic/update", params=payload, auth=(user,pswd))
print " "
if "good" in r.text:
print "Hello ", user, "!"
print "your IP was successfully updated to:", ip
print myhostname, "is up and running!"
if "nochg" in r.text:
print "Hello", user, "!"
print "Your IP", ip, "is still active, no change needed"
if "nohost" in r.text:
print "The given Host name", myhostname, "does not exist under specified account"
print "Please review your Host name and try again"
if "badauth" in r.text:
print "Login and/or Username incorrect"
print "Please correct your credentials and try again"
if "911" in r.text:
print "Sorry for the incovenience but we are experiencing some problems right now"
print "Please try again later"
print "noip.com says:", r.text
print " "
最简单的方法是将输出转到 noip.sh
中的文件:
python myapp.py > /tmp/myapp.out
然后当你想看到输出时,
tail -f /tmp/myapp.out
我制作了一个 python 程序,当我连接到 ppp network.The 应用程序请求 www.noip.com 到 link 我创建的主机的任何新 IP他们的网站。
/etc/ppp/ip-up.d/noip.sh #this script calls my python app
当我连接到 ppp 时,脚本 运行 正常,python 应用程序被触发并确实更改了我在 www.noip.com 上的 IP 地址,但我无法打印仅使用 print
向控制台发送消息。我的应用程序中有一些 print
语句,只有当我从命令行 运行 应用程序时才有效,例如 ./myapp.py
如果我的 python 应用程序是从后台调用的,如何显示消息?
这是我的 Python 代码:
#!/usr/bin/python
import requests
import netifaces as ni
user = 'xxxxxxx'
pswd = 'xxxxxxx'
ni.ifaddresses('ppp0')
ip = ni.ifaddresses('ppp0')[2][0]['addr']
myhostname = 'xxxxxxx'
payload = {'hostname' : myhostname , 'myip' : ip}
r = requests.get("http://dynupdate.no-ip.com/nic/update", params=payload, auth=(user,pswd))
print " "
if "good" in r.text:
print "Hello ", user, "!"
print "your IP was successfully updated to:", ip
print myhostname, "is up and running!"
if "nochg" in r.text:
print "Hello", user, "!"
print "Your IP", ip, "is still active, no change needed"
if "nohost" in r.text:
print "The given Host name", myhostname, "does not exist under specified account"
print "Please review your Host name and try again"
if "badauth" in r.text:
print "Login and/or Username incorrect"
print "Please correct your credentials and try again"
if "911" in r.text:
print "Sorry for the incovenience but we are experiencing some problems right now"
print "Please try again later"
print "noip.com says:", r.text
print " "
最简单的方法是将输出转到 noip.sh
中的文件:
python myapp.py > /tmp/myapp.out
然后当你想看到输出时,
tail -f /tmp/myapp.out