2024-09-26 04:49:41 发布
网友
我想这么做:
Bash代码:
grub --batch << EOF root (hd0,1) find /boot/grub/menu.lst setup (hd0) quit EOF
Python代码:
但这不管用。。 现在有人能用另一种方法来解决这个问题吗?在
非常感谢!在
解决方案是将脚本作为一个字符串发送:
script = ''' root (hd0,1) find /boot/grub/menu.lst setup (hd0) quit ''' print subprocess.Popen('grub', stderr=subprocess.STDOUT).communicate(script)[0]
shell=True不应该是必需的。在
shell=True
你可以做一些可怕的事情,比如:
subprocess.call('echo -e "root (hd0,1)\nfind /boot/grub/menu.lst\nsetup (hd0)\nquit" | grub batch', shell=True)
不过,我相信有更好的办法。在
解决方案是将脚本作为一个字符串发送:
shell=True
不应该是必需的。在你可以做一些可怕的事情,比如:
subprocess.call('echo -e "root (hd0,1)\nfind /boot/grub/menu.lst\nsetup (hd0)\nquit" | grub batch', shell=True)
不过,我相信有更好的办法。在
相关问题 更多 >
编程相关推荐