Bill, You should be able to execute this command via a STAF PROCESS START request. However, you must first understand a few "rules" for STAF option values when submitting a STAF service request as talked about in section "7.2 Option Value Formats" in the STAF User's Guide at http://staf.sourceforge.net/current/STAFUG.htm#HDROVFORM:
Since your command option value contains one or more spaces and you are submitting it via the command line, you need to enclose the value in double quotes. If you enclose the value in double quotes, the backslash character is the escape character. So to specify a double quote within the command, you need to escape it with a backslash (e.g. \"). Assuming the command you want to run is mysql -uuser -ppassword -ss -e 'use Database; select * from tbl1 where MD5 = md5("www.google.com");', then you could enclose the command value in double quotes and escape the double quotes within the command (e.g. around www.google.com) with a backslash as follows: # STAF local PROCESS START SHELL COMMAND "mysql -uuser -ppassword -ss -e 'use Database; select * from tbl1 where MD5 = md5(\"www.google.com\");'" RETURNSTDOUT STDERRTOSTDOUT WAIT 20s To verify what the actual command is that is being submitted to the STAF PROCESS service (after an escaped characters are processed, etc), you could enable STAF tracing for the ServiceRequest tracepoint and redirect STAF tracing to a file and verify that the command being submitted. For example: # staf local trace set destination to file /tmp/stafproc.out Response -------- # staf local trace enable tracepoint "ServiceRequest" Response -------- # STAF local PROCESS START SHELL COMMAND "mysql -uuser -ppassword -ss -e 'use Database; select * from tbl1 where MD5 = md5(\"www.google.com\");'" RETURNSTDOUT STDERRTOSTDOUT WAIT 20s Response -------- ... (The expected result from the mysql command should be in the returned file Data field) # tail /tmp/stafproc.out 20101025-04:25:50;90037152;00000001;TRACE Service Request - Client: local://local, Handle: 11, Process: STAF/Client, Request: enable tracepoint ServiceRequest 20101025-04:25:55;90037152;00000001;PROCESS Service Request - Client: local://local, Handle: 12, Process: STAF/Client, Request: START SHELL COMMAND :102:mysql -uuser -ppassword -ss -e 'use Database; select * from tbl1 where MD5 = md5("www .google.com");' RETURNSTDOUT STDERRTOSTDOUT WAIT 20s [r...@staf1e staf]# This allows you to verify that the STAF service request being submitted is actually what you intended. Note: Be sure to disable the ServiceRequest tracepoint because otherwise all STAF service requests will have a trace record logged. For example: . STAF local TRACE DISABLE TRACEPOINT "ServiceRequest" Or, if you submitted the START request to the PROCESS service via a program (e.g. using a STAF handle's submit method), then instead of enclosing the command option value that contains spaces in double quotes, you could instead use the length delimited format that is of the form :<Length>:<String> to "enclose" the command option value (then you don't need to escape any double quotes, etc within the command option value). STAF provides the "wrapData" method to do this for you. For example, in Python: from PySTAF import * import string import sys # Register a STAF handle try: handle = STAFHandle("MySQL/Test") except STAFException, e: print "Error registering with STAF, RC: %d" % e.rc sys.exit(e.rc) # Submit a PROCESS START request to run a mysql command command = 'mysql -uuser -ppassword -ss -e \'use DataBase; select * from tbl1 where MD5 = md5("www.google.com");\'' request = 'START SHELL COMMAND %s RETURNSTDOUT STDERRTOSTDOUT WAIT 20s' % (wrapData(command)) print '\nSTAF local PROCESS %s' % (request) result = handle.submit("local", "PROCESS", request) print '\nRC=%s' % (result.rc) print result.resultContext # Unregister (delete the STAF handle) result = handle.unregister() sys.exit(0) -------------------------------------------------------------- Sharon Lucas IBM Austin, luc...@us.ibm.com (512) 286-7313 or Tieline 363-7313 From: Smith Bill <yq...@yahoo.com.cn> To: staf-users@lists.sourceforge.net Cc: Apollo Deng <yq...@yahoo.com.cn> Date: 10/24/2010 12:19 PM Subject: [staf-users] How to execute a complex and nested request Hello, In Shell prompt we can execute this command and get the accurate result as expected: server-64:/usr/local/staf # mysql -uuser -puser -ss -e 'use Datebase; select * from tbl1 where MD5 = md5(“www.google.com");’ ----------------(A) As you see, the command which mentioned is composed and nested of follow commands: server-64:/usr/local/staf # mysql -uuser -puser -------------(B) //....get into mysql... mysql > use Datebase; -------------(C) mysql > select * from tbl1 where MD5 = md5(“www.google.com"); -------------(D) But I don‘t know how to use STAF to send the request to mysql as follows: STAF LOCAL PROCESS START SHELL (mysql_shell_name?) COMMAND "use Datebase;" RETURNSTDOUT STDERRTOSTDOUT WAIT -------------(E) or STAF LOCAL PROCESS START SHELL (mysql_shell_name?) COMMAND "select * from tbl1 where MD5 = md5('www.google.com');” RETURNSTDOUT STDERRTOSTDOUT WAIT -------------(F) So I tried to use Linux Shell to accept the whole request as follows, but it's come back result.result is a Numeric string equal HandleNumber at that moment. That wasn't the expect result(a string as md5('www.google.com')): STAF LOCAL PROCESS START SHELL COMMAND "mysql -uuser -puser -ss -e 'use Datebase; select * from tbl1 where MD5 = md5(\“www.google.com\");’ RETURNSTDOUT STDERRTOSTDOUT WAIT -------------(G) There is three questions: 1, If it is possible, I want use STAF to manipulate mysql database with step by step commands( (B) to (F) ). What name of the (mysql_shell_name?) will be specified? 2, Can we use Linux Shell to accept the request as (G) and get the expected result? Maybe there is some specifications to format (G) as I don't know about them, please tell me. 3, If we can't use methods1 or 2 to manipulate database. How can I resolve this problem? Can you illustrate it. Thank you. Bill ------------------------------------------------------------------------------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev _______________________________________________ staf-users mailing list staf-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/staf-users ------------------------------------------------------------------------------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev _______________________________________________ staf-users mailing list staf-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/staf-users