VMware {code} Community
joeranvl
Contributor
Contributor

Deleting file in Guest OS when using VMware Server

Is there any way to delete a file in the guest OS when using VMware Server with VIX? I see the VixVM_DeleteFileInGuest is since Workstation 6.0 and thus is unsupported.

I'm using an executable to perform an operation in the guest OS and makes it log to a file, which I in turn copy back to the client for analysis of the operation result. The thing is that the logger appends to the file instead of overwriting it, making the analysis hard (if not impossible, as I'm generalizing the operation for several similar executables with different syntax). In essence, all I need to do is to "empty" the file. One possible solution I can see myself is creating some simple batch file which deletes/overwrites the file (if it exists), but this is not optimal as it requires extra IO in my client (the name of the log file varies based on external parameters). Is it possible to overwrite the file by copying an empty file over it?

Thanks in advance for any advice on this!

Jøran

Edit. Just a brief clarification: I've also tried piping the result to a given field (which is an overwriting operation), but this doesn't work. I THINK this is because the executable I'm trying to run consumes more arguments (optionally) than I supply, and thus consumes the piping as well. If anyone knows how I can make this work, I'm just as happy :).

PS: Sorry if my English or the quality of my explanation is insufficient to understand the problem (it's late in the week Smiley Happy). If anything is unclear, please don't hesitate to ask.

Message was edited by: joeranvl

0 Kudos
2 Replies
lemke
VMware Employee
VMware Employee

Its crude, but you could use RunProgramInGuest with "/bin/rm" and the name of the file to do the delete. DeleteFileInGuest() essentially does that for you. Though if the logfile name isn't well-known, neither will help a lot. If the logfiles go into an otherwise empty directory, you may be able to simply delete the directory.
To empty it, on *nix you could just RunProgramInGuest "/bin/cat /dev/null > filename". But unless you need empty vs missing, the /bin/rm is simpler.
joeranvl
Contributor
Contributor

That certainly is an idea!

But, I forgot to specify that my Guest OSs are running Win XP. I guess something similar should be possible using the command line "del" operation, but I can't figure out how. I've tried executing c:\windows\system32\cmd.exe with "del c:\file_to_be_deleted" as parameters, but with no luck. Any idea how this could be done?

Thanks alot for your help so far :).

Edit:

Ah, solved it now. cmd requires the /C switch in order to execute the parameters it receives, thus the delete operation (for windows) is to execute c:\windows\ystem32\cmd.exe with the parameters "/C del \"c:\file_to_be_deleted\"" (escaped quotes must be used in order for cmd to accept files/paths with spaces).

Thanks buddy, I don't think I'd have solved this without your help!

Message was edited by: joeranvl

0 Kudos