473,395 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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.)

Sep 19 '05 #1
7 4709
Steve M wrote:
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'


That's not the same thing as the examples you give above. Namely, you're
missing the "salesforce.config.dir=" which is probably pretty
fundamental to telling the program where the salesforce config dir is.

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Sep 19 '05 #2
Steve M wrote:
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)


If you write
java -jar x.jar -Dwhatever=x
then -Dwhatever=x is passed as an argument to the main method of the
main class in x.jar.

If you write
java -Dwhatever=x -jar x.jar
then -Dwhatever=x is interpreted by java and put into the system properties.

Daniel
Sep 19 '05 #3
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)

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

No matter what I do, the program outputs that it cannot find the config
file.

*For at least one variation of the cmd string, I can print the value of
cmd and copy/paste it to the command line and the java program works
successfully, while for this same cmd string the java program fails
when invoked from Python.*

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.)

Sep 19 '05 #4
Steve M wrote:

About your main problem: I'm still convinced that it's the order of -jar
and -D that is important, see my other post.
I have tried (not entirely systematically but pretty exhaustively)
every combination of backslashes in the cmd string, e.g.:
-Dsalesforce.config.dir=c\:\\config
-Dsalesforce.config.dir=c:\\config
-Dsalesforce.config.dir=c\\:\config
-Dsalesforce.config.dir=c\\:\\config
etc.


A hint:
- if you're unsure how something must be entered as a literal, test it
in the interactive interpreter:
raw_input ('enter a path: ')

enter a path: c:\config
'c:\\config'

Daniel
Sep 20 '05 #5
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 : be**@cenix-bioscience.com
Cenix Website : http://www.cenix-bioscience.com

Sep 21 '05 #6
Neil Benn wrote:
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

Whoops you are using a raw string - you only need one backslash - the
java thing is still the same though

Cheers,

Neil

Sep 21 '05 #7
Thank you. I was able to fix it by putting the '-Dwhatever=x' bit
before the '-jar y.jar' bit. I had no idea this could matter.
Thanks all for the help.

Sep 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chuck Anderson | last post by:
I am trying to use ImageMagick from a Php script running under Windows XP. I have installed the latest version of ImageMagick - 6.2.1-7 and even tried backing up to version 5.5.7 (based on a...
11
by: PC | last post by:
It's obvious, that Windows XP has a Java 2 VM (including the SWING-module), because we can all run Java 2 applets in Internet Explorer. But what about the support for Java 2 Applications? I...
5
by: Noah | last post by:
Does anyone have a function to convert back and forth between NT style paths and POSIX style? It seems trivial, but I want to make sure I don't overlook some obscure detail. Is it a simple matter...
2
by: Patrick L. Nolan | last post by:
I'm trying to find a clean way to launch a Wordpad editor on Windows. By "clean", I mean that it should work on as many versions of Windows as possible, and it shouldn't require installing any...
19
by: Eric | last post by:
I'm trying to have some scripts run periodically on Windows XP and found the "Task Scheduler" did not execute my scripts. My scripts are of the form scriptName.py, and will run just by invoking that...
2
by: parthan | last post by:
We are running our c++ program, which uses JNI, as Windows services. Program is getting CLASSPATH env variable correctly and also initializes JVM successfully. After initializing JVM, programs...
11
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own...
0
by: Fran Maurais | last post by:
Is there a simple way for a Java application to display/log the Windows PID that has been assigned to it? I'm running on both Win2K and WinXP. I have several Java apps, which all run in their...
53
by: noahmd | last post by:
Okay, once-upon-a-time I tried to start programming by learning C. At the time I was younger and didn't really understand all that C had to offer. I eventually moved over to Microsoft's Visual...
34
by: Ben Sizer | last post by:
I've installed several different versions of Python across several different versions of MS Windows, and not a single time was the Python directory or the Scripts subdirectory added to the PATH...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.