LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   java and system calls (http://www.linuxquestions.org/questions/programming-9/java-and-system-calls-66569/)

aizkorri 06-19-2003 06:16 AM

java and system calls
 
Hi everyone, every time I try to do a system call that has inside some variable e.g:

helloWorld6Today is a C compiled program, imagine I have one for each day of the month.

String day=new String();
giveMeDay(day); --say it gives 6

Process egin=r.exec("/home/aizkorri/froga/helloWorld"+day+"Today");
egin.waitFor();


It just doesn't do anything, but If I do:

Process egin1=r.exec("/home/aizkorri/froga/helloWorld6Today");
egin1.waitFor();


It works.
And I think that it's pretty usual to use variables in that kind of calls, so do you have any idea what could be the problem?.

Looking_Lost 06-19-2003 06:22 AM

Try putting spaces in the string and see if it works


Process egin=r.exec("/home/aizkorri/froga/helloWorld "+day+" " +Today);

aizkorri 06-19-2003 06:50 AM

hi, well, but the file name doesn't have spaces, anyway, it doesn't even try to execute anything.

Looking_Lost 06-19-2003 07:52 AM

I see what you mean - I was reading it as two different parameters rather than one.

Only thing I can think of is giveMeDay is return a value you aren't expecting but I guess you've already checked that

I take it in the first example egin.WaitFor() returns a non-zero value showing there's been an error and at least it's tried to execute it.

aizkorri 06-19-2003 08:53 AM

thanks a lot, I found the error, it returns 1 but I forgot to put an important thing in the example: it does not work if I do:

Process egin=r.exec("/home/aizkorri/froga/helloWorld"+day+"*Today");
egin.waitFor();

Without the * it works fine, I was trying to execute more than one application at the same time but the * gives an error, I don't understand why, but it does.

Hko 06-19-2003 10:23 AM

Quote:

Originally posted by aizkorri
Without the * it works fine, I was trying to execute more than one application at the same time but the * gives an error, I don't understand why, but it does.
I guess that's because the Java Virtual Machine does no use a shell to execute your command. The interpretation ("expansion") of wildcards ( * ? [a-z] ...) is always done by a shell.

aizkorri 06-20-2003 01:54 AM

thanks for the explanation


All times are GMT -5. The time now is 02:03 AM.