微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

python-print 在启动时不会在控制台上显示输出

如何解决python-print 在启动时不会在控制台上显示输出

我在使用 openwrt,我想在启动时运行一个 python 脚本。为此,我编写了脚本并将其添加/etc/rc.local。启动后,当我执行 ps xa 时,我可以找到正在运行的脚本,但屏幕上没有打印任何内容。 我遵循的步骤如下 -

bootpython.py - 需要在启动时运行的 python 脚本

i=0

while(i<100):
        print("HELLO \n")
        i+=1

script.sh - 添加到 rc.local 的脚本

此脚本检查 ifconfig 中是否有 wlan0,然后才运行 python 代码。重启后,会创建saved.txt文件,里面写着HELLO。但是 /usr/bin/python3 /root/bootpython.py & 不会在屏幕上打印任何内容。如果我在不启动系统的情况下运行脚本 (/root/script.sh),它会在屏幕上打印 HELLO。我在这里错过了什么?

a=0

while [ $a -lt 100 ]
do
        if ( ifconfig | grep wlan0 )
        then
                a=`expr $a + 1`
                /usr/bin/python3 /root/bootpython.py > /root/saved.txt &
                /usr/bin/python3 /root/bootpython.py &
                break
        fi
done

/etc/rc.local

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

/root/script.sh &

exit 0

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。