我正在尝试运行 /bin/ls
通过 VirtualBox 提供的命令行界面 vboxmanage guestcontrol
.
关注 this documentation ,我运行这些命令:
vboxmanage startvm centos6;
vboxmanage guestcontrol "centos6" execute --image "/bin/ls" --username root --passwordfile pwd.txt --wait-exit --wait-stdout -- -l /usr;
我有以下
stdout
:Oracle VM VirtualBox Command Line Management Interface Version 5.0.0 (C) 2005-2015 Oracle Corporation All rights reserved.
Usage:
VBoxManage guestcontrol [--verbose|-v] [--quiet|-q] [--username ] [--domain ] [--passwordfile | --password ]
run [common-options] [--exe <path to executable>] [--timeout <msec>] [-E|--putenv <NAME>[=<VALUE>]] [--unquoted-args] [--ignore-operhaned-processes] [--no-profile] [--no-wait-stdout|--wait-stdout] [--no-wait-stderr|--wait-stderr] [--dos2unix] [--unix2dos] -- <program/arg0> [argument1] ... [argumentN]] start [common-options] [--exe <path to executable>] [--timeout <msec>] [-E|--putenv <NAME>[=<VALUE>]] [--unquoted-args] [--ignore-operhaned-processes] [--no-profile] -- <program/arg0> [argument1] ... [argumentN]] copyfrom [common-options] [--dryrun] [--follow] [-R|--recursive] <guest-src0> [guest-src1 [...]] <host-dst> copyfrom [common-options] [--dryrun] [--follow] [-R|--recursive] [--target-directory <host-dst-dir>] <guest-src0> [guest-src1 [...]] copyto [common-options] [--dryrun] [--follow] [-R|--recursive] <host-src0> [host-src1 [...]] <guest-dst> copyto [common-options] [--dryrun] [--follow] [-R|--recursive] [--target-directory <guest-dst>] <host-src0> [host-src1 [...]] mkdir|createdir[ectory] [common-options] [--parents] [--mode <mode>] <guest directory> [...] rmdir|removedir[ectory] [common-options] [-R|--recursive] <guest directory> [...] removefile|rm [common-options] [-f|--force] <guest file> [...] mv|move|ren[ame] [common-options] <source> [source1 [...]] <dest> mktemp|createtemp[orary] [common-options] [--secure] [--mode <mode>] [--tmpdir <directory>] <template> stat [common-options] <file> [...]
VBoxManage guestcontrol [--verbose|-v] [--quiet|-q]
list <all|sessions|processes|files> [common-opts] closeprocess [common-options] < --session-id <ID> | --session-name <name or pattern> <PID1> [PID1 [...]] closesession [common-options] < --all | --session-id <ID> | --session-name <name or pattern> > updatega|updateguestadditions|updateadditions [--source <guest additions .ISO>] [--wait-start] [common-options] [-- [<argument1>] ... [<argumentN>]] watch [common-options]
Syntax error: Unknown sub-command: 'execute'
最佳答案
是的,执行似乎不再适用于最新的 5.0.10 版本的 VirtualBox。尝试使用“运行”而不是“执行”和“--exe”而不是“--图像”。
此外 --wait-exit 已被抑制。
这是我现在正在使用的命令:$ VBoxManage --nologo guestcontrol "Windows7-64" run --exe "C:\Windows\SysWOW64\cmd.exe" foo.bat --username myname --verbose --wait-stdout --wait-stderr -- "/c" "f:\path\foo.bat" "arg1" "f:" "arg3"
该命令在 OS/X 上执行,以便在 Windows 64 位上执行带有三个参数的批处理文件 foo.bat。第二个参数“f:”是对应于我的程序所在的 OS/X 目录的 windows frive。
就我而言,此批处理文件使用 windows 'cmake' 以便在 Windows 64 上编译 C 程序。它是交叉编译的替代方法,有时更好,因为您可以使用具有更高性能的 native 编译器,并且可以在其真实环境中测试可执行文件。
但是,“run ---exe”与之前的“execute --image”有些不同,因为如果该命令在终端 shell 中运行良好,我会在 emacs 下使用“compile”命令遇到困难,可能是因为 --wait-exit不存在了。难点在于 VirtualBox VM 以高 CPU 消耗运行并且不会停止。
但是从 bash 来看,它看起来与以前非常相似。
VBoxManage 的当前文档抑制了 'execute' 和 '--image' 但使用过时(并且不再有效)选项的旧示例仍然存在,不幸的是增加了困惑。
更新:在 VirtualBox 5(我的是 5.2.6)上,我正在做$ VBoxManage --nologo guestcontrol "Windows7-64" run --exe "C:\\Windows\\system32\\cmd.exe" foo.bat --username myname --verbose --wait-stdout --wait-stderr -- "C:\Windows\SysWOW64\cmd.exe" "/c" "f:\path\foo.bat" "arg1" "f:" "arg3"
直接启动 64 位 cmd.exe 不再有效。
关于command-line-interface - 未知子命令 : 'execute' when using guestcontrol option,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33471119/