View Full Version : java runtime, and bash

08-12-2004, 08:04 PM
I think I have read at least 20 or so of the posts, and have not seen this question answered yet.
I want to run 3 consecutive commands on the system.
Runtime rt = Runtime.getRuntime();
process pr = rt.exec("cdparanoia -w 1 track1; cdparanoia -w 2 track2");
Is this valid?
I want to have linux execute mutiple bash commands one after another.
or should I loop it like so.

Runtime rt = Runtime.getRuntime();
String CommandString;
process pr;
for (int x=0;x<NumberOfTracks;x++)
CommandString="cdparanoia -w "+x+" track"+x;
pr = rt.exec(CommandString);

by the way I have read the page
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html (http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html)

08-12-2004, 09:05 PM
I want to have linux execute mutiple bash commands one after another. Like this
mplayer * -shuffle && echo "done" && exit

08-13-2004, 06:47 PM
thanks for the response.
I have a follow up question for you.

mplayer * -shuffle && echo "done" && exit
Will the && wait to execute the next command after the prior one has completed.
also what is the difference between what you wrote and the following

mplayer * -shuffle; echo "done"; exit

08-13-2004, 07:05 PM
The && is a conditional test. The order of statements are run left to right, as soon as one is deemed to be false, execution halts, no further statements are run. When using the semi-colon, that is a command separator, all statements are executed in order.

$ echo "1" && true && echo "2"

$ echo "1" && false && echo "2"

$ echo "1"; false; echo "2"

08-13-2004, 08:02 PM
thanks hammer.
another question involving bash commands and script files.
I was advised in this thread.
to use io processes.
how would I have a bash script send input/output data to the java interface?

08-14-2004, 02:39 PM
>>... to the java interface?
Don't know, this primarily a C/C++ programming forum.

08-14-2004, 03:51 PM
then let me rephrase the question for a more specific need.
Since I want to be able to do this in c, c++, and java.
how would I have a bash script and c/c++ program communicate to each other?
would I write everything to a .txt file and read it in on either side or is there another way?

08-14-2004, 04:30 PM
It depends on what you want to "communicate". Are we talking about long running programs, where both the script and program stay running indefinately, chatting to each other?

If C/C++ you can use popen(), if you're compiler supports it. You could also use pipes.

08-15-2004, 10:58 AM
does java support posix signals, mabey you could catch some of those?