我想向我的树莓派上的所有 bash 终端广播消息。
我知道有 wall 命令来执行该步骤,我可以使用 os.system python 模块来执行该命令。
但是,运行命令“wall text.txt”需要 sudo 权限。有没有办法将 wall 命令与 python 的 stdin 一起使用?
确实需要超级用户才能运行wall
带有输入文件,man
says:
NAME
wall - write a message to users
SYNOPSIS
wall [file]
DESCRIPTION
Wall displays the contents of file or, by default, its standard input, on the terminals of all currently logged in users.
Only the super-user can write on the terminals of users who have chosen to deny messages or are using a program which automatically denies messages.
Reading from a file is refused when the invoker is not superuser and the program is suid or sgid.
但你可以这样做:
$ echo hello hello >text.txt
$ python
Python 2.7.1 (r271:86832, Mar 18 2011, 09:09:48)
[GCC 4.5.0 20100604 [gcc-4_5-branch revision 160292]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.system('cat text.txt | wall')
Broadcast Message from mak@vader
(/dev/pts/14) at 10:31 ...
hello hello
Broadcast Message from mak@vader
(/dev/pts/14) at 10:31 ...
hello hello
0
>>>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)