473,554 Members | 3,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 sforcedataloade r.jar -Dsalesforce.con fig.dir=CONFIG_ DIRECTORY

They also give an example:

java -Dsalesforce.con fig.dir=c:\conf ig -jar sforcedataloade r.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 sforcedataloade r.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 4719
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 sforcedataloade r.jar -Dsalesforce.con fig.dir=CONFIG_ DIRECTORY

They also give an example:

java -Dsalesforce.con fig.dir=c:\conf ig -jar sforcedataloade r.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 sforcedataloade r.jar -Dc:\config'


That's not the same thing as the examples you give above. Namely, you're
missing the "salesforce.con fig.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 sforcedataloade r.jar -Dsalesforce.con fig.dir=CONFIG_ DIRECTORY

They also give an example:

java -Dsalesforce.con fig.dir=c:\conf ig -jar sforcedataloade r.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 sforcedataloade r.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 sforcedataloade r.jar -Dsalesforce.con fig.dir=CONFIG_ DIRECTORY

They also give an example:

java -Dsalesforce.con fig.dir=c:\conf ig -jar sforcedataloade r.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 sforcedataloade r.jar
-Dsalesforce.con fig.dir=c:\conf ig'
os.system(cmd)

I have tried (not entirely systematically but pretty exhaustively)
every combination of backslashes in the cmd string, e.g.:
-Dsalesforce.con fig.dir=c\:\\co nfig
-Dsalesforce.con fig.dir=c:\\con fig
-Dsalesforce.con fig.dir=c\\:\co nfig
-Dsalesforce.con fig.dir=c\\:\\c onfig
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.con fig.dir=c\:\\co nfig
-Dsalesforce.con fig.dir=c:\\con fig
-Dsalesforce.con fig.dir=c\\:\co nfig
-Dsalesforce.con fig.dir=c\\:\\c onfig
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 sforcedataloade r.jar -Dsalesforce.con fig.dir=CONFIG_ DIRECTORY

They also give an example:

java -Dsalesforce.con fig.dir=c:\conf ig -jar sforcedataloade r.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 sforcedataloade r.jar
-Dsalesforce.con fig.dir=c:\conf ig'
os.system(cm d)

<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 sforcedataloade r.jar -Dsalesforce.con fig.dir=c:\conf ig'
os.system(cmd)

use

cmd = r'java -Dsalesforce.con fig.dir=c:\\con fig -jar sforcedataloade r.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 sforcedataloade r.jar -Dsalesforce.con fig.dir=CONFIG_ DIRECTORY

They also give an example:

java -Dsalesforce.con fig.dir=c:\conf ig -jar sforcedataloade r.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 sforcedataloade r.jar
-Dsalesforce.con fig.dir=c:\conf ig'
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 sforcedataloade r.jar -Dsalesforce.con fig.dir=c:\conf ig'
os.system(cm d)

use

cmd = r'java -Dsalesforce.con fig.dir=c:\\con fig -jar sforcedataloade r.jar'
os.system(cm d)

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
7073
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 recommendation I found during a Google search), but I can not get ImageMagick to work in Php (using exec or system). ImageMagick works from a Windows...
11
12236
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 would just like to run an application packed in a JAR-file on Windows XP: JavaProg.jar (Java Archive Resource). But without installing a SDK, i don't...
5
18096
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 of translating / and \ characters? FYI, I need a Python function that does what cygpath does so that I can run a script on either NT or UNIX or...
2
2848
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 extra software. I assume everyone has win32api and its friends. The problem is to find the path to wordpad.exe. At first I just copied the path...
19
5800
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 name in the Command Prompt. Has anyone used the Windows Task Scheduler to run .py scripts, and if so isthere some intracacy to it? Is there a...
2
4944
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 makes a JNI call FindClass() for getting java class.But FindClass method returns NULL even though java class exists in the CLASSPATH. Same program...
11
3601
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 rules when it comes to file paths. A lot of Microsoft installers for example, and also installers of other companies, do not work because they handle...
0
8981
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 own VM. They are started in separate DOS command windows via a visual basic script. If I look in Windows Task Manager, I see XX number of "java.exe"...
53
5292
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 Basic. It was nice to be able to design a visual application with no effort (too bad I didn't really learn the ins and outs of programming) Long...
34
3927
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 environment variable. Every time, I've had to go through and add this by hand, to have something resembling a usable Python installation. No such...
0
7584
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7512
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7783
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8023
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7547
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6129
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5426
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2009
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.