1

如何使用 vmrun 在 vmware 中运行命令,来宾机器上的命令是 (echo %PROGRAMFILES%) .. 来宾机器应该返回命令结果的值...怎么做???请建议

4

3 回答 3

1

我需要做类似的事情并发现了这个悬而未决的问题。这是我的解决方案。

@ECHO OFF

REM Set up abbreviations that we'll be using a lot.
SET VMRUN="C:\Program Files (x86)\VMware\VMware VIX\vmrun.exe" -T ws -gu Administrator -gp password
SET VMX="C:\Users\whoever\Documents\Virtual Machines\Windows\Windows.vmx"
SET GUEST_COMSPEC="C:\WINDOWS\system32\cmd.exe"

REM Tried to do this in one line, but couldn't figure out the quoting.
%VMRUN% CreateTempfileInGuest %VMX% >%TEMP%\GuestTmp.txt || GOTO :CantCreate
FOR /F "delims=;" %%F IN ( %TEMP%\GuestTmp.txt ) DO SET GTEMP=%%F

REM The batch file is a one-liner that echos the variable into a file.
REM It could be generated dynamically and copied to the guest
REM but I didn't want to complicate things any further.
%VMRUN% runProgramInGuest %VMX% %GUEST_COMSPEC% "/c C:\echo-ProgramFiles.bat %GTEMP%"
%VMRUN% CopyFileFromGuestToHost %VMX% %GTEMP% %TEMP%\GuestOut.txt
%VMRUN% DeleteFileInGuest %VMX% %GTEMP%

REM Do something with the result and delete the temp files.
TYPE %TEMP%\GuestOut.txt
DEL %TEMP%\GuestOut.txt %TEMP%\GuestTmp.txt
GOTO :EOF

:CantCreate
REM Provide details on any problems.
TYPE %TEMP%\GuestTmp.txt 1>&2
DEL %TEMP%\GuestTmp.txt
EXIT 100

这是来宾主机上的批处理文件。如您所见,这非常简单。我无法重定向以在 runProgramInGuest 中工作(可能没有足够的实验),所以我只是将文件作为命令行参数传递。

@echo %PROGRAMFILES% >%1
于 2014-07-10T15:33:54.077 回答
0

我不得不使用 runProgramInGuest 将输出捕获到文件中,将文件复制回我的主机并使用它这就是我使用的解决方案。

于 2014-01-29T22:28:58.237 回答
0

在此处查看vmrun命令。您需要来宾操作系统命令runScriptInGuest

我没有检查命令,但它应该是这样的。请验证。

vmrun -T server -h https://xps:8333/sdk -u user -p mypassword -gu administrator -gp guestpaswd 
  runScriptInGuest "[Vol1] win2008-1/win2008-1.vmx" "echo %PROGRAMFILES%"
于 2014-01-28T08:55:15.877 回答