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

Steve M sjmaster at gmail.com
Mon Sep 19 23:06:19 CEST 2005


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 -Dc:\config'
os.system(cmd)

I have tried (not entirely systematically but pretty exhaustively)
every combination of backslashes in the cmd string, e.g.:
 -Dc\:\\config
 -Dc:\\config
 -Dc\\:\config
 -Dc\\:\\config
 etc.

No matter what I do, the program outputs that it cannot find the config
file. I cannot tell whether this is a java thing (why are there three
different styles for argument on the same command line? In addition to
"-jar xxx" and "-Dxxx=yyy" you can also put "xxx=yyy" for some
options... wth?), Windows lame cmd.exe shell (is that program invoked
by Python's os.system function?), or something else that is messing up.
It drivin me crazy though. (Come to think of it, Windows paths have
been a persistent thorn in my side for two years of Python development
at my company.)

Anybody have any suggestions?

p.s. 1. I would like to qualify the claim above that the example works
at the command-line. I'm not completely certain exactly which form of
invocation was successful at the command line, but at least one of them
was and that one definitely didn't work from Python.
2. I have a work-around available to me, which is that the program will
look for the configuration file in the current directory if the
command-line option isn't specified. I'd much rather be able to specify
a directory on the command line, so that I can have multiple
simultaneous invocations, and so that I can have the configuration file
not be in the directory where the Python program is, or alternatively
not have to change my directory (since I don't fully appreciate the
implications for other parts of my program  - this thing runs
asynchronously.)




More information about the Python-list mailing list