Windows paths, Java, and command-line arguments, oh my!

Neil Benn benn at cenix-bioscience.com
Wed Sep 21 06:03:37 EDT 2005


Steve M wrote:

>Well, apparently I fried my brain trying to sort this out. There is a
>typo in my example code in the post but not in my real program. (I know
>it is a no-no when asking help on c.l.py but I simplified some details
>from the real code in order not to confuse the issues. Probably
>backfired by this point.) Below is the post with the error fixed and
>one sentence added (to clarify why the error in my original post really
>was not the problem). Thanks for any advice.
>---
>I'm trying to invoke a Java command-line program from my Python program
>on Windows XP. I cannot get the paths in one of the arguments to work
>right.
>
>The instructions for the program describe the following for the
>command-line arguments:
>
>java -jar sforcedataloader.jar -Dsalesforce.config.dir=CONFIG_DIRECTORY
>
>They also give an example:
>
>java -Dsalesforce.config.dir=c:\config -jar sforcedataloader.jar
>
>If I type the example above at the cmd.exe command line the thing works
>(assuming I have the config file in c:\config). What doesn't work is
>these two lines:
>
>cmd = r'java -jar sforcedataloader.jar
>-Dsalesforce.config.dir=c:\config'
>os.system(cmd)
>
><snip>
>  
>
Unless you have fixed your typo in a different place, you have the same 
problem as before.  There are two issues, you need to escape the 
backslash and you have the java properties line in the wrong place.  
Instead of:

cmd = r'java -jar sforcedataloader.jar -Dsalesforce.config.dir=c:\config' 
os.system(cmd)

use

cmd = r'java -Dsalesforce.config.dir=c:\\config -jar sforcedataloader.jar'
os.system(cmd)

Neil

-- 

Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 47
D-01307
Dresden
Germany

Tel : +49 (0)351 4173 154
e-mail : benn at cenix-bioscience.com
Cenix Website : http://www.cenix-bioscience.com




More information about the Python-list mailing list