Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Eclipse IDE Environment
Eclipse IDE Environment [message #526908] Tue, 13 April 2010 09:31 Go to next message
Eclipse UserFriend
I've got the following code:
process = Runtime.getRuntime().exec("gs -version");


When I compile it and run it from command line, it's successful.
But when I run it from the Eclipse IDE it throws an exception.
When I replace "gs" with the full path it works (in both Eclipse and Command Line).

I've tried setting the environment variable in run configuration but it still doesn't work.

Here's the stack trace:
java.io.IOException: Cannot run program "gs": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
at java.lang.Runtime.exec(Runtime.java:593)
at java.lang.Runtime.exec(Runtime.java:431)
at java.lang.Runtime.exec(Runtime.java:328)
at clris.batchdownloader.TestJDBC.main(TestJDBC.java:17)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:53)
at java.lang.ProcessImpl.start(ProcessImpl.java:91)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
... 4 more

My "Environment Variable" Path Entry:
Variable: gs
Value: /opt/local/bin/gs

Any thoughts??
Re: Eclipse IDE Environment [message #527005 is a reply to message #526908] Tue, 13 April 2010 12:17 Go to previous messageGo to next message
Eclipse UserFriend
vispatel85@gmail.com wrote:
> I've got the following code:
> process = Runtime.getRuntime().exec("gs -version");
>
>
> When I compile it and run it from command line, it's successful. But
> when I run it from the Eclipse IDE it throws an exception.
> When I replace "gs" with the full path it works (in both Eclipse and
> Command Line).

Try setting the working directory, in the launch configuration, to wherever it
is you're running it from the command line.
Re: Eclipse IDE Environment [message #527008 is a reply to message #527005] Tue, 13 April 2010 12:48 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the try. But I don't think it's that. I've been able to run that command from anywhere, including the folder where why compiled code is. Any other ideas? Because I'm all out.
Re: Eclipse IDE Environment [message #527041 is a reply to message #527008] Tue, 13 April 2010 15:32 Go to previous messageGo to next message
Eclipse UserFriend
<vispatel85@gmail.com> wrote in message
news:hq2797$3ri$1@build.eclipse.org...
> Thanks for the try. But I don't think it's that. I've been able to run
> that command from anywhere, including the folder where why compiled code
> is. Any other ideas? Because I'm all out.

When you run from the command line, you invoking the command from a shell.
The shell processes commands by looking for them in the PATH variable. When
you use Runtime.exec, you are invoking the command directly without the
assistance of a shell to go looking for the file. You have to either give
the full path or invoke the shell process with the command as an argument.
Re: Eclipse IDE Environment [message #527067 is a reply to message #527041] Tue, 13 April 2010 17:12 Go to previous messageGo to next message
Eclipse UserFriend
David -
thanks for your thoughts. But what I don't understand is, why does my java program work when I compile/run from the command line. But it doesn't work when I compile/ run from Eclipse.

What do I need to do to make it work in Eclipse?
Re: Eclipse IDE Environment [message #527204 is a reply to message #526908] Wed, 14 April 2010 09:15 Go to previous message
Eclipse UserFriend
vispatel85@gmail.com wrote:
> I've got the following code:
> process = Runtime.getRuntime().exec("gs -version");
>
>
> When I compile it and run it from command line, it's successful. But
> when I run it from the Eclipse IDE it throws an exception.
> When I replace "gs" with the full path it works (in both Eclipse and
> Command Line).

As mentioned, your shell (command line) is exporting a useful PATH. In
eclipse, it must not be (which is possible if you launch eclipse from an
icon but not the command line).

To make it work in eclipse ... use the full path to your executable.
Depending on the user's PATH means that it can fail depending on changes
to the PATH.

The other alternative is to edit the env variables in your launch config
(Run>Run Configurations) and make sure that PATH is defined and matches
what you can see in your shell.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm
Previous Topic:Fixing a compile error requires closing an unrelated project
Next Topic:Setting build path has encountered a problem
Goto Forum:
  


Current Time: Tue Apr 15 03:01:12 EDT 2025

Powered by FUDForum. Page generated in 0.05953 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top