如何使用vmrun在vmware中运行命令,命令是来宾计算机上的(echo%PROGRAMFILES%).. 并且客机应该返回命令结果的值...怎么做?请建议
答案 0 :(得分: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
答案 1 :(得分:0)
在这里查看vmrun命令。您需要Guest OS Command 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%"
答案 2 :(得分:0)
我不得不使用runProgramInGuest 将输出捕获到文件 将文件复制回我的主机并使用它 那是我用过的溶液。