use of runtime

Hello can anyone help me? i am trying to execute perl using a java aplication. I use that code:

...

String eje = ("perl ireval.pl -j adhoc.qrels -trec < viperprueba.txt");

Runtime rt = Runtime.getRuntime();

try{

Process p= rt.exec(eje);

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

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

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

br.close();

p.destroy();

...

the problem is that it doesn't work, perl doesn't execute.

i think that is the fact that i use "<" anyone know someway to resolve it. Thanks

[653 byte] By [alejandro82a] at [2007-10-2 21:36:47]
# 1

If perl doesn't execute it's because exec doesn't know where to find it. Try specifying the full path.

As for the <, no, that won't work. < > | & and others are interpreted by the shell (e.g. bash, zsh, tcsh...), which is not present when you exec() like this. You can do something like this. Check the docs for your shell of preference for details, and of course use your proper full paths: eje = "/bin/bash -c '/usr/bin/perl ireval.pl -j adhoc.qrels -trec < viperprueba.txt'";

and then exec that.

Also, read this if you haven't already:

http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

jverda at 2007-7-14 0:51:02 > top of Java-index,Java Essentials,Java Programming...
# 2
Thanks for your attention, but this still doesn't work i will keep triying. Thanks very much.
alejandro82a at 2007-7-14 0:51:02 > top of Java-index,Java Essentials,Java Programming...
# 3
> Thanks for your attention, but this still doesn't> work i will keep triying. Thanks very much.Okay. If you get stuck, post again, with details of exactly what you're doing and exactly what "doesn't work" means.
jverda at 2007-7-14 0:51:02 > top of Java-index,Java Essentials,Java Programming...
# 4

well what doesn't work is that i want to retrieve the information that throws the execution of:

/bin/bash -c '/usr/bin/perl ireval.pl -j adhoc.qrels -trec < viperprueba.txt'

when i put it in the shell it show me the results i whant to view, but when i execute it in a java application whit exec, it doesn't do anything to me because like you said me doesn't undestand <. What i want is a way to say exec to use < viperprueba.txt, and i haven't find it yet. Some idea more? Thanks

alejandro82a at 2007-7-14 0:51:02 > top of Java-index,Java Essentials,Java Programming...
# 5

I don't know what you mean by "want exec to use < ..."

Exec does not understand <. bash understands it.

You need to narrow down where the problem is.

Try execing this: "/bin/bash -c 'ls > /tmp/zzz'"

Does that work? If not, what exactly happens.

Do you have /bin/bash?

Is perl in /usr/bin?

When you take the exact command /bin/bash -c '/usr/bin/perl ireval.pl -j adhoc.qrels -trec < viperprueba.txt'

into a command line, does that work?

jverda at 2007-7-14 0:51:02 > top of Java-index,Java Essentials,Java Programming...
# 6
If adhoc.qrels is a file, you'll probably have to specify a full path to it also.
jverda at 2007-7-14 0:51:02 > top of Java-index,Java Essentials,Java Programming...
# 7

"/bin/bash -c 'ls > /tmp/zzz'"

Does that work? If not, what exactly happens.

when i put it in the method exec it doesn't do anithing and doesn't create the file zzz

Do you have /bin/bash? yes

Is perl in /usr/bin?yes

When you take the exact command

/bin/bash -c '/usr/bin/perl ireval.pl -j adhoc.qrels -trec < viperprueba.txt'

into a command line, does that work? YES

like you see is very rare. this is the code i am using:

import java.io.*;

public class j{

public static void main(String args[]){

// String eje2 = ("perl ireval.pl -j adhoc.qrels -trec < viperprueba.txt");

Runtime rt = Runtime.getRuntime();

try{

Process p= rt.exec("/bin/bash -c 'ls'");

//BufferedWriter bw = new BufferedWriter (new OutputStreamWriter(p.getOutputStream()));

//OutputStream out = p.getOutputStream();

//out.write("< riperprueba.txt".getBytes());

//p.getOutputStream().close();

//p.waitFor();

//bw.write("< viperprueba.txt");

//bw.newLine();

//bw.write("< viperprueba.txt");

//bw.write("ireval.pl -j adhoc.qrels -trec < viperprueba.txt");

//bw.close();

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

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

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

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

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

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

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

br.close();

//p.waitFor();

//System.out.println(p.exitValue() + "ww");

p.destroy();

//rt.runFinalization();

FileWriter fw = new FileWriter("al.txt");

System.out.println("hace algo?");

}catch(IOException e){System.out.println("Error al ejecutar el proceso " + e);}

// catch(InterruptedException e){System.out.println("Error al ejecutar el proceso " + e);}

}

}

you see something extrange. Thanks again for your time

alejandro82a at 2007-7-14 0:51:02 > top of Java-index,Java Essentials,Java Programming...
# 8
well i close the problem for today, tomorroy i will continue. Thanks again
alejandro82a at 2007-7-14 0:51:02 > top of Java-index,Java Essentials,Java Programming...