Runtime.exec() not finding certain programs.

D

Dave Rudolf

Hey all,

I am using the Runtime.exec() method do start other programs in Windows.
One of which is actually another java program, albeit started by a batch
file. When I run the batch file from the explorer or a command window,
it all works just fine. However, if I try to run it with
Runtime.execute(), it can't find java.exe (which the batch file needs)
in the execution path.

So, I had code that looked something like this:

Process process = Runtime.getRuntime().exec(
new String[]{
fullDirectory.getAbsolutePath() + "\\crayola_oblongata.bat" },
new String[ 0 ],
fullDirectory );

The batch file simply starts the java program, like so:

java.exe -jar crayola_oblongata_gui.jar crayonsh.exe

I get a run-time error which indicates to me that the system can't find
java.exe in the execution path

'java.exe' is not recognized as an internal or external command,
operable program or batch file.

I get the same error if I try to get cmd.exe to start the program for
me, like so:

Process process = Runtime.getRuntime().exec(
new String[]{
"cmd.exe", "/c", "crayola_oblongata.bat" },
new String[ 0 ],
fullDirectory );

Now, if I put java.exe directly into the arguments to exec(), like so

Process process = Runtime.getRuntime().exec(
new String[]{
"java.exe", "-jar", "crayola_oblongata_gui.jar", "crayonsh.exe" },
new String[ 0 ],
fullDirectory );

Then it finds java.exe, but I get the following very puzzling exception:

java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:161)
at javax.swing.ImageIcon.<init>(ImageIcon.java:147)
at
com.sun.java.swing.plaf.windows.WindowsFileChooserUI$ShortCutPanel.<init>(WindowsFileChooserUI.java:622)
at
com.sun.java.swing.plaf.windows.WindowsFileChooserUI.updateUseShellFolder(WindowsFileChooserUI.java:489)
at
com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installComponents(WindowsFileChooserUI.java:347)
at
javax.swing.plaf.basic.BasicFileChooserUI.installUI(BasicFileChooserUI.java:130)
at
com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installUI(WindowsFileChooserUI.java:176)
at javax.swing.JComponent.setUI(JComponent.java:449)
at javax.swing.JFileChooser.updateUI(JFileChooser.java:1701)
at javax.swing.JFileChooser.setup(JFileChooser.java:345)
at javax.swing.JFileChooser.<init>(JFileChooser.java:320)
at javax.swing.JFileChooser.<init>(JFileChooser.java:273)
at crayon.FrmMain.<init>(Unknown Source)
at crayon.FrmMain.<init>(Unknown Source)
at crayon.CrayolaOblongata.<init>(Unknown Source)
at crayon.CrayolaOblongata.main(Unknown Source)
Exception in thread "main"


So, any guesses as to how I might fix this problem?

Thanks.

Dave
 
M

muthuishere

Include one more cmd in crayola_oblongata.bat

set PATH=%PATH%;{path of java compiler }




Hey all,

I am using the Runtime.exec() method do start other programs in Windows.
One of which is actually another java program, albeit started by a batch
file. When I run the batch file from the explorer or a command window,
it all works just fine. However, if I try to run it with
Runtime.execute(), it can't find java.exe (which the batch file needs)
in the execution path.

So, I had code that looked something like this:

Process process = Runtime.getRuntime().exec(
new String[]{
fullDirectory.getAbsolutePath() + "\\crayola_oblongata.bat" },
new String[ 0 ],
fullDirectory );

The batch file simply starts the java program, like so:

java.exe -jar crayola_oblongata_gui.jar crayonsh.exe

I get a run-time error which indicates to me that the system can't find
java.exe in the execution path

'java.exe' is not recognized as an internal or external command,
operable program or batch file.

I get the same error if I try to get cmd.exe to start the program for
me, like so:

Process process = Runtime.getRuntime().exec(
new String[]{
"cmd.exe", "/c", "crayola_oblongata.bat" },
new String[ 0 ],
fullDirectory );

Now, if I put java.exe directly into the arguments to exec(), like so

Process process = Runtime.getRuntime().exec(
new String[]{
"java.exe", "-jar", "crayola_oblongata_gui.jar", "crayonsh.exe" },
new String[ 0 ],
fullDirectory );

Then it finds java.exe, but I get the following very puzzling exception:

java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:161)
at javax.swing.ImageIcon.<init>(ImageIcon.java:147)
at
com.sun.java.swing.plaf.windows.WindowsFileChooserUI$ShortCutPanel.<init>(WindowsFileChooserUI.java:622)
at
com.sun.java.swing.plaf.windows.WindowsFileChooserUI.updateUseShellFolder(WindowsFileChooserUI.java:489)
at
com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installComponents(WindowsFileChooserUI.java:347)
at
javax.swing.plaf.basic.BasicFileChooserUI.installUI(BasicFileChooserUI.java:130)
at
com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installUI(WindowsFileChooserUI.java:176)
at javax.swing.JComponent.setUI(JComponent.java:449)
at javax.swing.JFileChooser.updateUI(JFileChooser.java:1701)
at javax.swing.JFileChooser.setup(JFileChooser.java:345)
at javax.swing.JFileChooser.<init>(JFileChooser.java:320)
at javax.swing.JFileChooser.<init>(JFileChooser.java:273)
at crayon.FrmMain.<init>(Unknown Source)
at crayon.FrmMain.<init>(Unknown Source)
at crayon.CrayolaOblongata.<init>(Unknown Source)
at crayon.CrayolaOblongata.main(Unknown Source)
Exception in thread "main"

So, any guesses as to how I might fix this problem?

Thanks.

Dave
 
D

Dave Rudolf

Nope, that isn't the problem. java.exe is in the %PATH% variable, so
adding it again doesn't help.



Include one more cmd in crayola_oblongata.bat

set PATH=%PATH%;{path of java compiler }




Hey all,

I am using the Runtime.exec() method do start other programs in Windows.
One of which is actually another java program, albeit started by a batch
file. When I run the batch file from the explorer or a command window,
it all works just fine. However, if I try to run it with
Runtime.execute(), it can't find java.exe (which the batch file needs)
in the execution path.

So, I had code that looked something like this:

Process process = Runtime.getRuntime().exec(
new String[]{
fullDirectory.getAbsolutePath() + "\\crayola_oblongata.bat" },
new String[ 0 ],
fullDirectory );

The batch file simply starts the java program, like so:

java.exe -jar crayola_oblongata_gui.jar crayonsh.exe

I get a run-time error which indicates to me that the system can't find
java.exe in the execution path

'java.exe' is not recognized as an internal or external command,
operable program or batch file.

I get the same error if I try to get cmd.exe to start the program for
me, like so:

Process process = Runtime.getRuntime().exec(
new String[]{
"cmd.exe", "/c", "crayola_oblongata.bat" },
new String[ 0 ],
fullDirectory );

Now, if I put java.exe directly into the arguments to exec(), like so

Process process = Runtime.getRuntime().exec(
new String[]{
"java.exe", "-jar", "crayola_oblongata_gui.jar", "crayonsh.exe" },
new String[ 0 ],
fullDirectory );

Then it finds java.exe, but I get the following very puzzling exception:

java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:161)
at javax.swing.ImageIcon.<init>(ImageIcon.java:147)
at
com.sun.java.swing.plaf.windows.WindowsFileChooserUI$ShortCutPanel.<init>(WindowsFileChooserUI.java:622)
at
com.sun.java.swing.plaf.windows.WindowsFileChooserUI.updateUseShellFolder(WindowsFileChooserUI.java:489)
at
com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installComponents(WindowsFileChooserUI.java:347)
at
javax.swing.plaf.basic.BasicFileChooserUI.installUI(BasicFileChooserUI.java:130)
at
com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installUI(WindowsFileChooserUI.java:176)
at javax.swing.JComponent.setUI(JComponent.java:449)
at javax.swing.JFileChooser.updateUI(JFileChooser.java:1701)
at javax.swing.JFileChooser.setup(JFileChooser.java:345)
at javax.swing.JFileChooser.<init>(JFileChooser.java:320)
at javax.swing.JFileChooser.<init>(JFileChooser.java:273)
at crayon.FrmMain.<init>(Unknown Source)
at crayon.FrmMain.<init>(Unknown Source)
at crayon.CrayolaOblongata.<init>(Unknown Source)
at crayon.CrayolaOblongata.main(Unknown Source)
Exception in thread "main"

So, any guesses as to how I might fix this problem?

Thanks.

Dave
 
G

Gordon Beaton

Process process = Runtime.getRuntime().exec(
new String[]{
fullDirectory.getAbsolutePath() + "\\crayola_oblongata.bat" },
new String[ 0 ],
fullDirectory );

If you expect the child to inherit the parent's environment (including
the PATH), specify null, not "new String[0]". The empty array leaves
the child with an empty environment.

/gordon
 
D

Dave Rudolf

Gordon said:
Process process = Runtime.getRuntime().exec(
new String[]{
fullDirectory.getAbsolutePath() + "\\crayola_oblongata.bat" },
new String[ 0 ],
fullDirectory );


If you expect the child to inherit the parent's environment (including
the PATH), specify null, not "new String[0]". The empty array leaves
the child with an empty environment.

/gordon

Muchos gracias!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top