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

时间:2014-10-21 17:51:44

标签: 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(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在代码中是有意的。

0 个答案:

没有答案