我无法通过commands.getstatusoutput()
函数执行此命令。
from commands import getstatusoutput as x
command = """guestfish << _EOF_
add %s
run
mount /dev/sda1 /
write /etc/sysconfig/network "NETWORKING=yes\\nHOSTNAME=%s\\n"
_EOF_""" % ( "/tmp/foo", "foobar")
x(command)
给出错误:
sh: line 5: warning: here-document at line 0 delimited by end-of-file (wanted `_EOF_')
sh: -c: line 6: syntax error: unexpected end of file
这看起来很简单,但似乎无法弄清楚。只是为了做一个注释,\\n
在代码中是有意的。