运行命令行包含重定向>>在Guest VM中

时间:2015-11-02 13:01:23

标签: command-line-interface virtualbox io-redirection

要在名为ls -l /home的来宾VM中运行myvm,我们可以在主机上运行:

vboxmanage --nologo guestcontrol myvm --username root --password xxxx run  --exe /bin/ls --wait-stdout --wait-stderr -- ls/arg0 -l /home

现在,如果我们尝试使用相同的方法运行此命令echo "this is new line " >> /home/u1/sample.txt

vboxmanage --nologo guestcontrol myvm --username root --password xxxx run  --exe /bin/echo --wait-stdout --wait-stderr -- echo/arg0 "this is new line " >> /home/u1/sample.txt 

- >我有:

  

bash:/home/u1/sample.txt:没有这样的文件或。

我添加引号:

vboxmanage --nologo guestcontrol myvm --username root --password xxxx run  --exe /bin/echo --wait-stdout --wait-stderr -- echo/arg0 '"this is new line " >> /home/u1/sample.txt'

- >访客VM中没有任何更改,我的意思是/home/u1/sample.txt

任何想法?我知道我使用VirtualBox 5.0.0

1 个答案:

答案 0 :(得分:1)

因为:

command > redirect

类似于:

/bin/sh -c "command > redirect"

然后:

vboxmanage --nologo guestcontrol myvm --username root --password xxxx run  --exe /bin/sh --wait-stdout --wait-stderr -- sh/arg0 -c "echo this is new line >> /home/u1/sample.txt"