VMware {code} Community
wsaxon
Contributor
Contributor
Jump to solution

Capturing fault messages for methods w/o return values

I've written a script to shut down groups of VMs in my cluster. I get a view of a VirtualMachine object, check the value of the guest.toolsRunningStatus property and then call ShutdownGuest() if the tools are running.

Sometimes the guest.toolsRunningStatus property is set to 'guestToolsRunning' even when the tools are not running, e.g. when the VMware Tools Service is stopped in a Windows VM. In these cases, SOAP Fault ToolsUnavailable messages are printed to stderr. How can I capture these faults without redirecting stderr and parsing the messages? ShutdownGuest() does not return anything.

0 Kudos
1 Solution

Accepted Solutions
schue
Contributor
Contributor
Jump to solution

Hi,

you have to do silly things :smileygrin: see the following code:

my $blah = undef;

eval{

$blah = guest.toolsRunningStatus();

};

if($@) {

print "your Exception";

}

When in the eval-block occours an error thats piped in stderr, the error message will be pipe in $@.

So when $@ is set, in $@ will be the SoapFault-Object.

I hope that will help you.

Henning

View solution in original post

0 Kudos
1 Reply
schue
Contributor
Contributor
Jump to solution

Hi,

you have to do silly things :smileygrin: see the following code:

my $blah = undef;

eval{

$blah = guest.toolsRunningStatus();

};

if($@) {

print "your Exception";

}

When in the eval-block occours an error thats piped in stderr, the error message will be pipe in $@.

So when $@ is set, in $@ will be the SoapFault-Object.

I hope that will help you.

Henning

0 Kudos