Python 使用命令模块的getstatusoutput执行包含“here document”的命令

Python 使用命令模块的getstatusoutput执行包含“here document”的命令,python,python-2.6,Python,Python 2.6,我无法通过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(co

我无法通过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)

这看起来很简单,但似乎无法理解。请注意,\\n在代码中是有意的。

在字符串末尾添加一个换行符。终止标记不能有前导空格。抱歉,各位,我仍然不清楚答案。
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