Run command in STAX Service

First, I would like to thank Dave and Sharon, who helped me out from deep trouble. You guys are really kind and helpful!

Run a command with quote from STAX service is easier than from Process service, Sharon’s has explained it quite clear.

The equivalent element in a STAX job for a PROCESS START WAIT request is the <process> element, not the <stafcmd> element. The <stafcmd> element is used for STAF service requests other than a PROCESS START WAIT request. Using the <process> element will eliminate most of the quoting issues. Please see the STAX User’s Guide for detailed information on the <process> element and examples. Also, note that in Python, if you enclose a literal using a single quote, then it can contain double quotes without having to escape them (and vice versa).

   1: <process name="'ListSnapShot'"> 
   2:     <location>'VMHost'</location> 
   3:     <command>'vmrun listSnapshots "C:\VM\win2003_standard\Windows Server 2003 Standard Edition.vmx"' </command>
   4:     <stderr mode="'stdout'"/> 
   5:     <returnstdout/> 
   6: </process> 



   1: <script> 
   2: vmxFileName = 'C:\VM\win2003_standard\Windows Server 2003 Standard Edition.vmx' 
   3: </script> 
   5: <process name="'ListSnapShot'"> 
   6:     <location>'VMHost'</location> 
   7:     <command>'vmrun listSnapshots "%s"' % (vmxFileName)</command> 
   8:     <stderr mode="'stdout'"/> 
   9:     <returnstdout/> 
  10: </process> 


Notice: The #7 line in the latter example show the way of using one string parameter, for parameters more than one, should be like this:

<command>'vmrun start "%s" "%s"' % (vmfile,snapshot)</command>

When running STAX service with map-type argument, especially with quotes in one of the values, simply follow this format:

STAF local STAX execute file test.xml ARGS "{’key1′:’value1′, ‘key2’:’value need to be quoted’}" wait returnresult

Notice the outer quote is double-quote and inner quotes are single-quote.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s