File Won't Run with Runtime On Windows XP

Discussion in 'Java' started by Hal Vaughan, Sep 2, 2007.

  1. Hal Vaughan

    Hal Vaughan Guest

    I have a program that uses OpenOffice and the associated classes. This is
    not an OpenOffice problem, but a strange problem of trying to run a
    program. For several reasons, my program uses a script to run programs.
    This lets me set arguments in the script (with some programs, others don't
    need it) and it makes it a bit easier to keep track of paths across
    different platforms.

    I have a DOS .bat file that runs OpenOffice on Windows XP. I've never had a
    problem with it in several years. If I run it from the command line, I can
    see it's working just fine. But if I run that same .bat file from within
    Java, the file runs but it doesn't run OpenOffice. Here's the .bat file:

    SET ooo_file=$ooo_dir\program\soffice
    if "%1" == "" "%ooo_file%" -quickstart >nul
    if "%1" == "-quickstart" "%ooo_file%" -quickstart >nul
    if "%1" == "-headless" "%ooo_file%" -headless >nul

    Which I shortened, while testing, to this:

    SET ooo_file=$ooo_dir\program\soffice
    "%ooo_file%" -quickstart >nul

    As I said, it works just fine (in either version) from the command line.
    Then I run it in Java, using this:

    try {
    Runtime.getRuntime().exec(sFile);
    } catch (Exception e) {
    sysConfig.log("error", "Cannot Run Command (RunFile): " + sFile + ",
    Error: " + e);
    TNConfig.printTrace(e);
    }

    While the functions in the error trapping section are my own, they're not
    the issue and when I'm having problems, they're never used, so no error is
    thrown when I try this.

    I've used this setup, on Windows XP, for a few years and there hasn't been a
    problem. Now when I use it, the script works fine from the command line.
    I know it is being run from within Java. I changed the ">nul" to redirect
    to a file, the file was created but was empty. (There is no output from
    OpenOffice normally, so I didn't expect output.) That tells me Java is
    running the batch file and, supposedly, running OpenOffice, but the program
    just isn't running (or is running quickly and exits).

    Previously I had used Java 1.4.2 or Java 5, but this system is running Java
    6. I've tested this on another XP system using Java 6 and I don't have
    this problem.

    I figure there must be something different about the environment within the
    Runtime.getRuntime().exec() environment that a program can detect that
    varies from the command line. It might also be likely that this change is
    in Java 6 but not in earlier versions.

    Can anyone shed some light on this problem?

    Thanks!

    Hal
    Hal Vaughan, Sep 2, 2007
    #1
    1. Advertising

  2. Hal Vaughan wrote:
    > I have a program that uses OpenOffice and the associated classes. This is
    > not an OpenOffice problem, but a strange problem of trying to run a
    > program. For several reasons, my program uses a script to run programs.
    > This lets me set arguments in the script (with some programs, others don't
    > need it) and it makes it a bit easier to keep track of paths across
    > different platforms.
    >
    > I have a DOS .bat file that runs OpenOffice on Windows XP. I've never had a
    > problem with it in several years. If I run it from the command line, I can
    > see it's working just fine. But if I run that same .bat file from within
    > Java, the file runs but it doesn't run OpenOffice. Here's the .bat file:
    >
    > SET ooo_file=$ooo_dir\program\soffice
    > if "%1" == "" "%ooo_file%" -quickstart >nul
    > if "%1" == "-quickstart" "%ooo_file%" -quickstart >nul
    > if "%1" == "-headless" "%ooo_file%" -headless >nul
    >
    > Which I shortened, while testing, to this:
    >
    > SET ooo_file=$ooo_dir\program\soffice
    > "%ooo_file%" -quickstart >nul
    >
    > As I said, it works just fine (in either version) from the command line.
    > Then I run it in Java, using this:
    >
    > try {
    > Runtime.getRuntime().exec(sFile);
    > } catch (Exception e) {
    > sysConfig.log("error", "Cannot Run Command (RunFile): " + sFile + ",
    > Error: " + e);
    > TNConfig.printTrace(e);
    > }
    >
    > While the functions in the error trapping section are my own, they're not
    > the issue and when I'm having problems, they're never used, so no error is
    > thrown when I try this.
    >
    > I've used this setup, on Windows XP, for a few years and there hasn't been a
    > problem. Now when I use it, the script works fine from the command line.
    > I know it is being run from within Java. I changed the ">nul" to redirect
    > to a file, the file was created but was empty. (There is no output from
    > OpenOffice normally, so I didn't expect output.) That tells me Java is
    > running the batch file and, supposedly, running OpenOffice, but the program
    > just isn't running (or is running quickly and exits).
    >
    > Previously I had used Java 1.4.2 or Java 5, but this system is running Java
    > 6. I've tested this on another XP system using Java 6 and I don't have
    > this problem.
    >
    > I figure there must be something different about the environment within the
    > Runtime.getRuntime().exec() environment that a program can detect that
    > varies from the command line. It might also be likely that this change is
    > in Java 6 but not in earlier versions.
    >
    > Can anyone shed some light on this problem?
    >

    Try running a test script that displays the environment variables rather
    than trying to run Open Office etc and see what the differences are
    between what it shows in good and bad environments.


    --
    martin@ | Martin Gregorie
    gregorie. | Essex, UK
    org |
    Martin Gregorie, Sep 2, 2007
    #2
    1. Advertising

  3. Hal Vaughan

    Roedy Green Guest

    On Sun, 02 Sep 2007 13:36:20 -0400, Hal Vaughan
    <> wrote, quoted or indirectly quoted someone
    who said :

    > Runtime.getRuntime().exec(sFile);


    you can't run a bat file directly. You must run a command processor
    and pass the bat file as a parameter.

    See http://mindprod.com/jgloss/exec.html
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Sep 3, 2007
    #3
  4. Hal Vaughan

    Hal Vaughan Guest

    Roedy Green wrote:

    > On Sun, 02 Sep 2007 13:36:20 -0400, Hal Vaughan
    > <> wrote, quoted or indirectly quoted someone
    > who said :
    >
    >> Runtime.getRuntime().exec(sFile);

    >
    > you can't run a bat file directly. You must run a command processor
    > and pass the bat file as a parameter.
    >
    > See http://mindprod.com/jgloss/exec.html


    So why would it have worked before?

    Is there something I was doing that would work sometimes that isn't working
    now?

    Hal
    Hal Vaughan, Sep 3, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    447
  2. =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=

    My portal won't run on Windows 2003

    =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=, Dec 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    338
    =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=
    Dec 30, 2006
  3. SD_V897
    Replies:
    5
    Views:
    3,116
    SD_V897
    Nov 11, 2009
  4. DavidB
    Replies:
    0
    Views:
    97
    DavidB
    Jun 10, 2006
  5. Replies:
    11
    Views:
    260
    Mohit Sindhwani
    Nov 9, 2007
Loading...

Share This Page