Virtual machine 如何使用vmrun在vmware中运行命令,命令是(echo%PROGRAMFILES%)

Virtual machine 如何使用vmrun在vmware中运行命令,命令是(echo%PROGRAMFILES%),virtual-machine,vmware,vmrun,Virtual Machine,Vmware,Vmrun,如何使用vmrun在vmware中运行命令,该命令在来宾计算机上是(echo%PROGRAMFILES%)。。 来宾计算机应该返回命令结果的值。。。怎么做???请建议查看此处的命令。您需要Guest OS命令runScriptInGuest 我没有检查命令,但它应该是这样的。请核实一下 vmrun -T server -h https://xps:8333/sdk -u user -p mypassword -gu administrator -gp guestpaswd runScrip

如何使用vmrun在vmware中运行命令,该命令在来宾计算机上是(echo%PROGRAMFILES%)。。 来宾计算机应该返回命令结果的值。。。怎么做???请建议查看此处的命令。您需要Guest OS命令
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%"

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

我需要做一些类似的事情,发现了这个未回答的问题。这是我的解决办法

@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

我试过这个,但不起作用。。以下是我在“C:\\Program Files(x86)\\VMware\\VMware Workstation\\vmrun.exe”-gu localname-gp password runScriptInGuest“C:\\Users\\Administrator\\Documents\\Virtual Machines\\Windows 8 32_ws\\Windows 8 32_ws.vmx”“C:\\Windows\\system32\\cmd.exe”“/C echo%PROGRAMFILES%”中所做的操作基本上,我需要运行这个命令并在主机中捕获命令的输出。。。我不确定使用vmrun命令是否可以做到这一点。我可以确认runScriptInGuest在Windows中不能正常工作(至少不是我使用的Windows 7和VMWare 9)。是的,正如samwyse的回答所示,执行一个先前复制到guest的BAT文件runProgramInGuest就是解决方案。