0

我有一个可以在虚拟机中触发的脚本。

但是,我想将参数传递给脚本。我通常将脚本作为“>>test.bat user1”运行

争论是“user1”。有人可以帮助修改以下命令以通过争论吗?

VBoxManage --nologo guestcontrol "sample1" run --exe "C:\Users\sample1\Desktop\test.bat" --username sample1 --password sample2 --wait-stdout

我也试过跑步

VBoxManage --nologo guestcontrol "sample1" run --exe "C:\Users\sample1\Desktop\test.bat user1" --username sample1 --password sample2 --wait-stdout

但这是不对的,我对上述命令的结果为:

C:\Program Files\Oracle\VirtualBox>VBoxManage --nologo guestcontrol "sample3" run --exe "C:\Users\sample1\Desktop\test.bat user1"  --username sample1 --password sample2 --wait-stdout
VBoxManage.exe: error: No such file or directory on guest
VBoxManage.exe: error: Details: code VBOX_E_IPRT_ERROR (0x80bb0005), component GuestProcessWrap, interface IGuestProcess, callee IUnknown
VBoxManage.exe: error: Context: "WaitForArray(ComSafeArrayAsInParam(aWaitStartFlags), gctlRunGetRemainingTime(msStart, cMsTimeout), &waitResult)" at line 1485 of file VBoxManageGuestCtrl.cpp

也试过

VBoxManage --nologo guestcontrol "sample1" run --exe "C:\Users\sample1\Desktop\test.bat" --username sample1 --password sample2 --wait-stdout --user1

 

Usage:

 

VBoxManage guestcontrol     <uuid|vmname> [--verbose|-v] [--quiet|-q]
                              [--username <name>] [--domain <domain>]
                              [--passwordfile <file> | --password <password>]
                              run [common-options]
                              [--exe <path to executable>] [--timeout <msec>]
                              [-E|--putenv <NAME>[=<VALUE>]] [--unquoted-args]
                              [--ignore-operhaned-processes] [--profile]
                              [--no-wait-stdout|--wait-stdout]
                              [--no-wait-stderr|--wait-stderr]
                              [--dos2unix] [--unix2dos]
                              -- <program/arg0> [argument1] ... [argumentN]]

 

VBoxManage.exe: error: Unknown option: --user1
4

2 回答 2

0

正如我所看到的,这个问题与vboxmanage无关,只是一个如何在批处理文件中传递引用命令行参数的问题。

在批处理文件中,命令行参数按照它们在命令行中出现的顺序被引用为 %1、%2、%3 等。因此:

这是一个简单的单行 bat 文件,名为 doit.bat

echo %1 %2 %3

这是它的执行:

C:\>doit firstparm secondparm thirdparm

C:\>echo firstparm secondparm thirdparm
firstparm secondparm thirdparm
于 2020-07-23T12:15:51.310 回答
0

来自 VBoxManage 文档:

VBoxManage guestcontrol <uuid|vmname> run [common-options] --exe <path to executable> 
[--timeout <msec>] [-E|--putenv <NAME>[=<VALUE>]] [--unquoted-args]
[--ignore-operhaned-processes] [--profile] [--no-wait-stdout|--wait-stdout]
[--no-wait-stderr|--wait-stderr] [--dos2unix] [--unix2dos] -- <program/arg0> [argument1] ... [argumentN]]

请试试

VBoxManage --nologo guestcontrol "sample1" run --exe "C:\Users\sample1\Desktop\test.bat" --username sample1 --password sample2 --wait-stdout -- user1

--我在之前的评论中遗漏了

于 2020-07-23T12:38:20.553 回答