Thread: java runtime, and bash

  1. #1
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    java runtime, and bash

    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.
    Code:
    Runtime rt = Runtime.getRuntime();
    process pr = rt.exec("cdparanoia -w 1 track1; cdparanoia -w 2 track2");
    p.waitFor();
    Is this valid?
    I want to have linux execute mutiple bash commands one after another.
    or should I loop it like so.
    Code:
    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);
      p.waitFor();
    }
    by the way I have read the page
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  2. #2
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    I want to have linux execute mutiple bash commands one after another.
    Like this
    Code:
    mplayer * -shuffle && echo "done" && exit

  3. #3
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    linuxdude,
    thanks for the response.
    I have a follow up question for you.
    Code:
    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
    Code:
    mplayer * -shuffle; echo "done"; exit
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    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.
    Code:
     $ echo "1" && true && echo "2"
     1
     2
     
     $ echo "1" && false && echo "2"
     1
     
     $ echo "1"; false; echo "2"
     1
     2
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    thanks hammer.
    another question involving bash commands and script files.
    I was advised in this thread.
    http://forum.java.sun.com/thread.jsp...rt=0&trange=15
    to use io processes.
    how would I have a bash script send input/output data to the java interface?
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>... to the java interface?
    Don't know, this primarily a C/C++ programming forum.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    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?
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    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.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    does java support posix signals, mabey you could catch some of those?
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Shell output into program during runtime
    By evilkillerfiggi in forum Linux Programming
    Replies: 3
    Last Post: 08-03-2006, 10:50 AM