Java Runtime executing problem

Hi all,

I have a problem when getting runtime to execute a string.

String verify_user_cmd="ldapsearch -h host.com -b \"ou=People,o=host.com,o=SDS\" uid" +GID +" cn |tail -1|cut -d= -f2";

I have verified that the string appeared as what I wanted(by using println to check the string), but when I performed the following:

Process p = Runtime.getRuntime().exec(verify_user_cmd);

BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));

System.out.println(br.readLine());

It returns null though I am able to execute the command successfully (with expected result) directly from the unix command prompt.

Any help is greatly appreciated.

Thanks,

Eugene

[739 byte] By [ET78a] at [2007-11-27 9:36:15]
# 1

The I/O redirection (such as you're doing with the | character) is done by the shell, and exec() doesn't run through the shell.

You can either do the redirection yourself, I suppose, by invoking exec for each process and then connecting the output of one process to the input of another. Or you could do the tail and the cut yourself.

But the easier thing would probably be to either create a shell script, and invoke that, or to run the shell and use the -c option or such to send the command string to that.

paulcwa at 2007-7-12 23:04:54 > top of Java-index,Java Essentials,Java Programming...
# 2
Given the 2 alternatives,1) How do I get the shell script to return the value if I chooses to run the shell script?2) How do I run the shell and use the -c option or such to send the command string?
ET78a at 2007-7-12 23:04:54 > top of Java-index,Java Essentials,Java Programming...
# 3
Case closed by executing using shell and -c option.
ET78a at 2007-7-12 23:04:54 > top of Java-index,Java Essentials,Java Programming...