Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

File Won't Run with Runtime On Windows XP

Thread view: 
Hal Vaughan - 02 Sep 2007 18:36 GMT
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
Martin Gregorie - 02 Sep 2007 19:48 GMT
> 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
[quoted text clipped - 51 lines]
>
> 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.

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Roedy Green - 03 Sep 2007 03:15 GMT
On Sun, 02 Sep 2007 13:36:20 -0400, Hal Vaughan
<hal@thresholddigital.com> 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
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Hal Vaughan - 03 Sep 2007 03:26 GMT
> On Sun, 02 Sep 2007 13:36:20 -0400, Hal Vaughan
> <hal@thresholddigital.com> wrote, quoted or indirectly quoted someone
[quoted text clipped - 6 lines]
>
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.