要在名为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
。
答案 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"