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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve M

    #1

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

  • Robert Kern

    #2
    Re: Windows paths, Java, and command-line arguments, oh my!

    Steve M wrote:[color=blue]
    > 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'[/color]

    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
    rkern@ucsd.edu

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

    Comment

    • Daniel Dittmar

      #3
      Re: Windows paths, Java, and command-line arguments, oh my!

      Steve M wrote:[color=blue]
      > 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)[/color]

      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

      Comment

      • Steve M

        #4
        Re: Windows paths, Java, and command-line arguments, oh my!

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

        Comment

        • Daniel Dittmar

          #5
          Re: Windows paths, Java, and command-line arguments, oh my!

          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.
          [color=blue]
          > 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.[/color]

          A hint:
          - if you're unsure how something must be entered as a literal, test it
          in the interactive interpreter:
          [color=blue][color=green][color=darkred]
          >>> raw_input ('enter a path: ')[/color][/color][/color]
          enter a path: c:\config
          'c:\\config'

          Daniel

          Comment

          • Neil Benn

            #6
            Re: Windows paths, Java, and command-line arguments, oh my!

            Steve M wrote:
            [color=blue]
            >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>
            >
            >[/color]
            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 : benn@cenix-bioscience.com
            Cenix Website : http://www.cenix-bioscience.com

            Comment

            • Neil Benn

              #7
              Re: Windows paths, Java, and command-line arguments, oh my!

              Neil Benn wrote:
              [color=blue]
              >Steve M wrote:
              >
              >
              >[color=green]
              >>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[/color]
              >
              >[color=green]
              >>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>
              >>
              >>
              >>
              >>[/color]
              >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
              >
              >
              >[/color]
              Whoops you are using a raw string - you only need one backslash - the
              java thing is still the same though

              Cheers,

              Neil

              Comment

              • Steve M

                #8
                Re: Windows paths, Java, and command-line arguments, oh my!

                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.

                Comment

                Working...