1.

Solve : How to open a file and examine its contents?

Answer»

Hi,

Let SAY I've a small tools called "vmchk.exe".
When i run vmchk.exe from a Command Prompt IN a "VMware Virtual Machine", the message "Runing inside VMWare <version 6>." is displayed.
When i run vmchk.exe NOT IN a VMware Virtual Machine, the message "Not runing inside VMWare." is displayed.

I will run the "vmchk.exe" program from within my program, redirecting the output from vmchk to a file (e.g., vmchk.exe >chkfile.dat).
Then, what command will open "chkfile.dat" and examine its contents to determine whether my program is "Running inside..." or "Not running inside..." a VMware Virtual Machine.

Regards
coucou
Realy anyone can help??? i'm sad!!!

May be i don't express myself as well. I'm trying again.

In fact, after runing vmchk.exe >chkfile.dat, i'll get a "Runing inside VMWare <version 6>." or ""Not runing inside VMWare."" text inside chkfile.dat file.

1)How to extract the text information from chkfile.dat to a variable ?
or
2) It is possible to pipe directly vmchk.exe to a variable?(vmchk.exe >to_a_variable instead of vmchk.exe >chkfile.dat).
Then i will COMPARE the variable with the message text

Regards
coucouYou could add a FOR statement after the vmchk.exe statement:

for /f "delims=!" %%a in (chkfile.dat) do echo %%a

Note: the delims parameter is just a dummy override of default delims (space & TAB). Presumably there is no ! in the output literal so %%a resolves to the entire string.

There are other ways to do this (tokens=1*) or you might be abe to pipe the output directly to a SET statement, but this is simple enough.

TNX Sidewinder for the help.

When i launch for /f "delims=!" %%a in (chkfile.dat) do echo %%a from a command prompt after vmchk.exe >chkfile.dat, i get "in was unexpected" display.
How do i correct that?

Quote

you might be abe to pipe the output directly to a SET statement
I like this.

Regards
coucou
The solution above was for inclusion in a batch file. At the command line, the proper format is:

for /f "delims=!" %a in (chkfile.dat) do echo %a

Just another example of the DOS follies. TNX agin Sidewinder,

Finally here my command
for /f "delims=!" %a in (chkfile.dat) do set check=%a

and here my small cmd
Code: [Select]@echo off
set vm=Runing inside VMWare <version 6>.

start / wait vmchk.exe >chkfile.dat
for /f "delims=!" %%a in (chkfile.dat) do set check=%%a

If vm=check Then vmtools.exe

else
endif It is correct?

It is there anyhow to pipe directly vmchk.exe >to_a_variable instead of to a file? If so, let me KNOW how.

Regards
coucouYou may be confusing redirection with piping. Redirection is used with devices (stdin, stdout, stderror, nul). The pipe is used to send data from one command to another.

Code: [Select]
for /f "delims=!" %%a in ('vmchk') do set check=%%a
if %check%=vm vmtools


From your previous posts, I thought %check% would resolve to "Runing inside VMWare ." or "Not runing inside VMWare.". If that's the case %check% will never equal the literal vm.

The command interpreter does not support a if/then/else/endif construct.

Hope this helps. I tested my small cmd in many ways without success.

What I'm looking to do is by launching vmcheck.cmd it will
1)call vmchk.exe
2)Check IN chkfile.dat file or a variable for "Runing inside VMWare <version 6>." text
3) IF so run vmtools .exe
4) else
5) endif or exit or stop the program runing
Have you any suggestion?Woowww!!! it works
Here the Code: [Select]@echo off
set vm=Runing inside VMWare <version 6>.

vmchk.exe >chkfile.dat
for /f "delims=!" %%a in (chkfile.dat) do set check=%%a

If "%check%" == "%vm%" vmtools.exe
I had not success to pipe the returned message "Runing inside VMWare <version 6>." from vmchk.exe >to_a_variable without using chkfile.dat file

Regards
coucouIf you want to go straight to a variable, the syntax is different:

Code: [Select]
for /f %%a in ('vmchk') do (
if %%a=Running vmtools
)

Wooww!
It works with 2 ==
Code: [Select]for /f %%a in ('vmchk') do (
if "%%a=="Runing inside VMWare <version 6>." vmtools.exe
)

coucou


Discussion

No Comment Found