Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Runtime.exec

1 view
Skip to first unread message

Sharmila Pillai

unread,
Feb 20, 2003, 7:25:46 AM2/20/03
to
Hi,

Runtime.exec("setenv EOUT_DIR /homes/sharmila/temp");

Gives the following error:

java.io.IOException: java.io.IOException: setenv EOUT_DIR
/homes/sharmila/temp: not found
at java.lang.UNIXProcess.<init>(UNIXProcess.java:143)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:566)
at java.lang.Runtime.exec(Runtime.java:491)
at java.lang.Runtime.exec(Runtime.java:457)
at CommandLine.main(CommandLine.java:32)

What am I doing wrong??
Any hints, please?

TIA,
Sharmila.

Justin Fowler

unread,
Feb 20, 2003, 7:32:02 AM2/20/03
to
Sharmila Pillai wrote:

> Sharmila.
try using the full path of setenv ie /bin/setenv (I Thing)
--
Justin Fowler
Software Engineer

jfow...@netspace.net.au
+61 0421 593 275

Gordon Beaton

unread,
Feb 20, 2003, 8:23:03 AM2/20/03
to

Several things:

- setenv is not a program, it is a shell builtin. To use a shell
builtin, you need to execute a shell. You could *concievably* do
this instead:

String[] cmd = {
"/bin/tcsh",
"-c",
"setenv EOUT_DIR /homes/sharmila/temp",
};
Runtime.getRuntime().exec(cmd);

- Runtime.exec() executes the command in a child process to the JVM.
There is little point in running a command that does nothing but
change its environment (and then terminates).

- it is not possible for one process to modify the environment of
another. In this case, you are (apparently) attempting to run a
child process and have it modify the environment of the parent.
This will never work.

Perhaps you could explain what you are trying to achieve here...

/gordon

--
[ do not send me private copies of your followups ]
g o r d o n . b e a t o n @ e r i c s s o n . c o m

Sharmila Pillai

unread,
Feb 20, 2003, 9:31:57 AM2/20/03
to
Thanks. It does work now.

> Several things:
>
> - setenv is not a program, it is a shell builtin. To use a shell
> builtin, you need to execute a shell. You could *concievably* do
> this instead:
>
> String[] cmd = {
> "/bin/tcsh",
> "-c",
> "setenv EOUT_DIR /homes/sharmila/temp",
> };
> Runtime.getRuntime().exec(cmd);
>
> - Runtime.exec() executes the command in a child process to the JVM.
> There is little point in running a command that does nothing but
> change its environment (and then terminates).
>

I am trying to set a variable and Runtime.exec a program whose output
depends on that variable.


> - it is not possible for one process to modify the environment of
> another. In this case, you are (apparently) attempting to run a
> child process and have it modify the environment of the parent.
> This will never work.
>
> Perhaps you could explain what you are trying to achieve here...
>
> /gordon

Thanks again,
Sharmila.

Robert J. Clark

unread,
Feb 20, 2003, 9:05:48 PM2/20/03
to
On Thu, 20 Feb 2003 14:31:57 +0000, Sharmila Pillai wrote:
>> Several things:
>>
>> - setenv is not a program, it is a shell builtin. To use a shell
>> builtin, you need to execute a shell. You could *concievably* do
>> this instead:
>>
>> String[] cmd = {
>> "/bin/tcsh",
>> "-c",
>> "setenv EOUT_DIR /homes/sharmila/temp",
>> };
>> Runtime.getRuntime().exec(cmd);
>>
>> - Runtime.exec() executes the command in a child process to the JVM.
>> There is little point in running a command that does nothing but
>> change its environment (and then terminates).
>>
>
> I am trying to set a variable and Runtime.exec a program whose output
> depends on that variable.

Then you should take a look at (one of) the other version of
Runtime.exec(), specifically:

Runtime.exec(String[] cmdarray, String[] envp)

Which allows you to provide an array of 'NAME=VALUE' environment variables
for the child process.

String[] cmd = {
"your_program",
"an_argument",
"another_argument",
};
String[] environment = {
"EOUT_DIR="/homes/sharmila/temp",
"HOME=/homes/sharmila",
"LIMBURGER=smells bad"
}

Runtime.getRuntime().exec(cmd, environment);

Check the docs at:

http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Runtime.html

- Rob

--
(to email me, remove "warez.")
Please do not send me email copies of newsgroup postings.

0 new messages