Sharon,
thank you again for the hints.
Unfortunately I still don't understand what to do. Especially the process of
breaking the <parms>-string into
single parameters isn't transparent to me.
Let me give an example:
A very simple program is written in C. It just prints its parameters to a file.
Here is the source code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
int
main(int argc, char **argv)
{
int i;
FILE *fp;
fp = fopen("/myhome/testcmd.out", "w");
if (fp == NULL) {
fprintf(stderr, "Error in fopen(): %s\n", strerror(errno));
exit(1);
}
for (i = 1; i < argc; i++) {
fprintf(fp, "Parameter %d: #%s#\n", i, argv[i]);
}
exit(0);
}
Before the program is called from STAX via <process>, a Python variable is
set to the contents of the <parms>-string and printed to STAXMon. There are
three parameters I want to transfer to my program: the first is a single digit 1
only, the second are the digits 2 and 3 separated by a space and enclosed by
quotes (which the program should receive, too) and the third parameter are the
digits 4 and 5 separated by a space and enclosed by single quotes, which also
are a part of the parameter.
Here is the <script> element:
<script>
testparms = '1 "2 3" \'4 5\''
print "Testparms = #%s#" % testparms
</script>
STAXMon shows:
Testparms = #1 "2 3" '4 5'#
When my program is executed by STAX, it writes to the file testcmd.out:
Parameter 1: #1#
Parameter 2: #2 3#
Parameter 3: #'4#
Parameter 4: #5'#
There are 4 parameters, not 3 and the quotes are not part of the second
parameter. So, I guess, the precise question should be, what are the rules
used in STAF to process the <parms>-string when building the argument
array for the "execv()"?
Or is there a possibility to give a list of strings, one for each parameter?
Bodo
________________________________
From: Sharon Lucas [mailto:luc...@us.ibm.com]
Sent: Friday, July 10, 2009 11:45 PM
To: Strösser, Bodo
Cc: 'staf-users@lists.sourceforge.net'
Subject: Re: [staf-users] STAX: How to format <parms> element content
Bodo,
The STAF colon-length-colon format is for an entire option value in a STAF
service request (as talked about in the STAF User's Guide).
You need to understand Python to know what characters in a string like this
need to be replaced. This isn't really a STAF/STAX question, but more of a
Python question on how to construct string literals. Please read section
"Using Python for Expression Evaluation" in the STAX User's Guide and you can
google for more information on Python.
For example, say you wanted to run the following command via a <process>
element in a STAX job:
myCommand -file: "C:\Program Files\myApp" -x: 'Hi'
you could specify:
<parms>"-file: \"C:\\Program Files\\myApp\" -x: 'Hi'"</parms>
or you could specify it as follows:
<parms>'-file: "C:\\Program Files\\myApp" -x: \'Hi\''</parms>
Python documentation provides complete information about how to construct
string literals such as the following information:
"There are several different ways to construct string literals in Python.
String literals can start and end with single quotes or double quotes. In
either case, the other kind of quote can be used safely inside the literal.
Within the quotation marks, special characaters are escaped using a backslash.
The list of escapes is based on C and is slightly different from Java's escape
list. Unlike Java, backslashes followed by characters not on the following
list of escapes are legal in strings, and are treated merely as normal
characters.
Backslash Escape Characters:
Escape character Meaning
---------------- -----------------------------------------
\\ Backslash (\)
\' Single quote (')
\" Double quote (")
\r Carriage return
\t Tab
\uxxxx Unicode 16-bit character value xxxx (hex)
\a Bell (ASCII character number 13)
\b Backspace
\f Formfeed
\n Linefeed or newline
\N{name} Unicode character identified by "name"
\Uxxxxxxxx Unicode 32-bit characer xxxxxxxx (hex)
\v Vertical tab character
\ooo Unicode 8-bit character in octal
\xhh hexadecimal
String literals may also begin and end with either three single or three double
quotes. A triple-quoted string may include newline characters (which would
ordinarily need to be escaped) or individual quotation marks.
"""some
long
string"""
A string literal may also have an r or R before the inital quote, to indicate a
"raw string". Inside a raw string, backslash escape does not work and
backslashes are treated as normal characters. Quotation marks may be escaped
in raw strings, but the backslash stays in the string.
>>> r"c:\program files"
'c:\\program files'
>>> r"\""
'\\"'
Notice that the raw string results in a normal string -- after the string is
created, you can't tell whether itwas created using the raw option. Raw
strings are just a flavor or string literal. They are often used in regular
expressions to keep them from looking even more like random noise."
So, in the future, you can look at Python documentation to get answers to
questions on Python (instead of posting to the staf-users mailing list).
Note, you also need to be careful when specifying a < or & within a STAX xml
file, or a { in a STAF service request option value that resolves variables:
- Also, note that XML processors assume that < always starts a tag and that &
always starts an entity reference, so you should avoid using those characters
for anything else. You must use the entity reference < instead of < and
entity reference & instead of & or else you'll get an XML parsing error.
- Also, note that STAF automatically resolves STAF variables in a PROCESS START
COMMAND and PARMS option, so if you need to specify a {, you need to escape it
with a caret, e.g. ^{
--------------------------------------------------------------
Sharon Lucas
IBM Austin, luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313
Strösser, Bodo <bodo.stroes...@ts.fujitsu.com>
07/10/2009 03:10 PM
To
"'staf-users@lists.sourceforge.net'" <staf-users@lists.sourceforge.net>
cc
Subject
[staf-users] STAX: How to format <parms> element content
Hi,
when starting a <process> in STAX, parameters for the process must be
specified in the <parms> element.
I need to handle the case of a number of strings containing one parameter each.
The strings might contain characters like Quotation marks, Single quotes or
Backslashes. How would I need to prepare the python string for the <parms>
element, so that the parameters are transfered to the process transparently?
The colon-length-colon method seems not to work here.
Best regards
Bodo
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at:
http://p.sf.net/sfu/Challenge_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users