Menu

Error if i wrap the command :- stafclient.stafexception: '"SC QUERY Audiosrv"' is not recognized as an internal or external command,operable program or batch file.

Help
2016-11-23
2016-11-25
  • Ganesh Markande

    Ganesh Markande - 2016-11-23

    Hi,

    I am getting following error when i wrap the command using STAFUtil.wrap(command).
    stafclient.stafexception: '"SC QUERY Audiosrv"' is not recognized as an internal or external command,operable program or batch file.

    Following request gives me the error :-

    STAF local Process START SHELL COMMAND STAFUtil.wrap(command) WAIT RETURNSTDOUT STDERRTOSTDOUT"

    Command = "SC QUERY <Service-Name>"

    If i exclude "STAFUtil.wrap()" then command executes fine.

    Following request gives successful results :-

    STAF local Process START SHELL COMMAND command WAIT RETURNSTDOUT STDERRTOSTDOUT"

    Command = "SC QUERY <Service-Name>"

     
  • Sharon Lucas

    Sharon Lucas - 2016-11-23

    How are you submitting the STAF PROCESS START request? Is this via the STAF command executable from a command prompt or .bat file? If so, there isn't a STAFUtils.wrap() function for the STAF command executable.

    Or are you using a <process> element in a STAX job? If so, here's an example of a STAX job that runs fine:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <!DOCTYPE stax SYSTEM "stax.dtd">
    
    <stax>
    
    <defaultcall function="main"/>
    
    <function name="main">
    
    <sequence>
    
      <script>
        service = 'Audiosrv'
        command = 'SC QUERY %s' % (service)
      </script>
    
      <process>
        <location>'local'</location>
        <command>command</command>
        <stderr mode="'stdout'"/>
        <returnstdout/>
      </process>
    
      <message log="1">'Process RC: %s  STAXResult: %s' % (RC, STAXResult)</message>
    
    </sequence>
    
    </function>
    
    </stax>
    

    Or are you submitting the PROCESS START via a Python script? If so, here's an example showing three different ways that work:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    #!/usr/bin/python
    
    from PySTAF import *
    import sys
    
    try:
        handle = STAFHandle("MyTest")
    except STAFException, e:
        print "Error registering with STAF, RC: %d" % e.rc
        sys.exit(e.rc)
    
    # Here's a PROCESS START example using the wrapData() function to wrap the COMMAND option's value
    
    command = "SC QUERY Audiosrv"
    request = "START SHELL COMMAND %s WAIT RETURNSTDOUT" % (wrapData(command))
    result = handle.submit("local", "PROCESS", request)
    
    if result.rc != 0:
        print "ERROR: Received RC: %d, Result: %s" % (result.rc, result.result)
        sys.exit(1)
    
    mc = unmarshall(result.result)
    output = mc.getRootObject()['fileList'][0]['data']
    print output
    
    # Here's a PROCESS START example using double quotes to wrap the COMMAND option's value
    # Note used single quotes around the request value so could use double quotes within it without
    # having to excape them.
    
    request = 'START SHELL COMMAND "%s" WAIT RETURNSTDOUT' % (command)
    result = handle.submit("local", "PROCESS", request)
    
    if result.rc != 0:
        print "ERROR: Received RC: %d, Result: %s" % (result.rc, result.result)
        sys.exit(1)
    
    mc = unmarshall(result.result)
    output = mc.getRootObject()['fileList'][0]['data']
    print output
    
    # Here's a PROCESS START example using double quotes to wrap the COMMAND option's value
    # Note since used double quotes around the request value have to escape the double quotes
    # with a backslash when used within the request value.
    
    request = "START SHELL COMMAND \" %s\" WAIT RETURNSTDOUT" % (command)
    result = handle.submit("local", "PROCESS", request)
    
    if result.rc != 0:
        print "ERROR: Received RC: %d, Result: %s" % (result.rc, result.result)
        sys.exit(1)
    
    mc = unmarshall(result.result)
    output = mc.getRootObject()['fileList'][0]['data']
    print output
    
    #############
    # Finish up #
    #############
    
    result = handle.unregister()
    
    if (result != STAFResult.Ok):
        print "Error unregistering with STAF, RC: %d" % result
        sys.exit(result)
    
    sys.exit(0)
    
     
  • Ganesh Markande

    Ganesh Markande - 2016-11-24

    I am submitting STAF request from JAVA using submit2() method.

     
  • Ganesh Markande

    Ganesh Markande - 2016-11-24

    I am creating a request object

    request = stafServiceCommandAction + " SHELL COMMAND " + STAFUtil.wrapData(command.toString().trim()) + " WAIT RETURNSTDOUT STDERRTOSTDOUT";

    Then submitting it to STAF submit2()

    handle.submit2(machineName,stafServiceName,request);

     
  • Sharon Lucas

    Sharon Lucas - 2016-11-25

    Works fine for me. Here's an example submitting a "SC QUERY Audiosrv" command and using STAFUtil.wrapData around it in a PROCESS START request:

    import com.ibm.staf.*;
    import java.util.*;
    
    public class ProcessWrapData
    {
        // This is the main command line entry point
    
        public static void main(String [] argv)
        {
            // Register with STAF
    
            try
            {
                handle = new STAFHandle("Process_WrapData_Test");
            }
            catch (STAFException e)
            {
                System.out.println(
                    "Error registering with STAF, RC: " + e.rc);
                System.exit(1);
            }
    
            // Submit a PROCESS START request using STADUtil.wrapData()
            // to "wrap" the command option value.
            String machineName = "local";
            String stafServiceName = "PROCESS";
            String command = "SC QUERY Audiosrv";
    
            String request = "START SHELL COMMAND " +
                STAFUtil.wrapData(command) +
                " RETURNSTDOUT STDERRTOSTDOUT WAIT";
    
            STAFResult result = handle.submit2(
                machineName, stafServiceName, request);
    
            if (result.rc != 0)
            {
                System.out.println("Error starting process, RC: " +
                                   result.rc + ", Additional Info: " + 
                                   result.result);
                System.exit(1);
            }
    
            STAFMarshallingContext mc = STAFMarshallingContext.unmarshall(
                result.result);
    
            System.out.println(mc);
        }
    
        private static STAFHandle handle;
    }
    

    Here's its output:

    C:\stax>java ProcessWrapData
    {
      Return Code: 0
      Key        : <None>
      Files      : [
        {
          Return Code: 0
          Data       :
    SERVICE_NAME: Audiosrv
            TYPE               : 20  WIN32_SHARE_PROCESS
            STATE              : 4  RUNNING
                                    (STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
            WIN32_EXIT_CODE    : 0  (0x0)
            SERVICE_EXIT_CODE  : 0  (0x0)
            CHECKPOINT         : 0x0
            WAIT_HINT          : 0x0
    
        }
      ]
    }
    
     

Log in to post a comment.