Problems with getRuntime().exec()

Hello!

I'd like to start a process which will run a C executable.

The C executable named dbc is placed in the folder

/home/swkm/services/rul_hyb/rul-1.0/bin and accepts as an argument the name of a database, for example, myDB

I tried the following code:

File f =new File(filePath);

Process process = Runtime.getRuntime().exec

(

new String[]

{

"dbc",

"myDB"

}, null,f

);

where filePath is the above mentioned path.

The problem is that I receive an:

java.io.IOException: java.io.IOException: dbc: not found

at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)

I tried the new Tiger version of ProcessBuilder in the following manner:

ProcessBuilder process =new ProcessBuilder

(

new String[]

{

"dbc",

"myDB"

}

);

process.directory(new File(path));

Process p=process.start();

but I got the same exception: "dbc not found"

Do you have any idea what is going wrong?

Thank you very much

With best regards,

Sorin

[1496 byte] By [Sorin_Ciolofana] at [2007-11-27 6:01:55]
# 1

Are you assuming that the executable executes from the directory defined by 'filePath' ? If so then this is wrong - the executable must be in a directory in the PATH environment variable or you must specify the full path to the executable.

The third argument in the exec() command is the working directory for the process and does not modify the PATH environment variable.

P.S. It does not matter whether you use Runtime.exec() or ProcessBuilder becauuse behind the scenes Runtime.exec() just wraps ProcessBuilder.

Message was edited by:

sabre150

sabre150a at 2007-7-12 16:42:31 > top of Java-index,Java Essentials,Java Programming...