[Biopython-dev] ApplicationResult and generic_run obsolete?

Peter biopython at maubp.freeserve.co.uk
Thu Aug 6 15:48:12 UTC 2009


On Thu, Aug 6, 2009 at 3:39 PM, Peter<biopython at maubp.freeserve.co.uk> wrote:
> Now, if you give subprocess a list, on Windows it must first be turned
> into a string, before subprocess can use the Windows API to run it.
> The subprocess function list2cmdline does this, but the conventions it
> follows are not universal.
>
> I have examples of working command line strings for ClustalW and PRANK
> where both the executable and some of the arguments have spaces in
> them. It seems the quoting I was using to make ClustalW (or PRANK)
> happy cannot be achieved via subprocess.list2cmdline (and I suspect
> this applies to other tools too).

e.g. This is a valid and working command line for PRANK, which works
both at the command line, or in Python via subprocess when given as
a string:

C:\repository\biopython\Tests>"C:\Program Files\prank.exe"
-d=Quality/example.fasta -o="temp with space" -f=11 -convert

Now, breaking up the arguments according to the description given in
the subprocess.list2cmdline docstring, I think the arguments are:

"C:\Program Files\prank.exe"
-d=Quality/example.fasta
-o="temp with space"
-f=11
-convert

Of these, the middle guy causes problems. By my reading of
the subprocess.list2cmdline docstring this is valid:

>>    2) A string surrounded by double quotation marks is
>>       interpreted as a single argument, regardless of white
>>       space or pipe characters contained within.  A quoted
>>       string can be embedded in an argument.

The example -o="temp with space" is a string surrounded by
double quotes, "temp with space", embedded in an argument.

Unfortunately, giving these five strings to subprocess.list2cmdline
results in a mess as it never checks to see if the arguments are
already quoted (as we have done for the program name and also
the output filename base). We can pass the program name in
without the quotes, and list2cmdline will do the right thing. But
there is no way for the -o argument to be handled that I can see.

This may be a bug in subprocess.list2cmdline, but it is certainly
a real limitation in my opinion.

So, it would appear that (on Windows) making our command line
wrappers act like lists (by defining __iter__) will not work in general.

The other approach which would allow our command line wrappers
to be passed directly to subprocess is to make them more string
like - but the subprocess code checks for string command lines
using isinstance(args, types.StringTypes) which means we would
have to subclass str (or unicode). I'm not sure if this can be made
to work yet...

Peter



More information about the Biopython-dev mailing list