Results 1 to 3 of 3
  1. #1
    keneid is offline Member
    Join Date
    Jun 2010
    Rep Power

    Default read commands from file and run it


    How can I read a text file with differents commands like ps aux, ls -al, etc. and run it?

    I using fileinputstream and runtime.
    I just need some help to find some examples to do that.

    This work->
    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec("c:\\test.exe -id=jallaf -password=jallaf run test");

    I want it to be like this:

    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec(file-with-command.txt + "-id=jallaf -password=jallaf run test");

    hope you understanding my problem.

  2. #2
    vineetkr211 is offline Member
    Join Date
    May 2010
    Rep Power


    Assuming you are working on unix platform, you need to run it as script(shell or perl). Just put all your commands in a file say "".
    Assign execute permission using chmod:-
    chmod 777

    Then, in Java do like this:-

    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec(relative-or-complete-path -of-file( + "-id=jallaf -password=jallaf run test");

  3. #3
    keneid is offline Member
    Join Date
    Jun 2010
    Rep Power


    thank you very much. it's work.

    But I have another runtime issue too.

    I want the java application read the string into a file.txt and put it in a runtime command.
    The issue is: I have a windows application in wine. The text file is for example
    cat file.txt
    c:\\program files\\shure\\shure.exe

    The java application should read this line and put it into here -->
    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec(c:\\program files\\shure\\shure.exe "any-command-for-shure");

    ("any-command-for-shure") is always in the java application - but the string in the text file will change. maybe somebody want to install shure in c:\shure\ so they have to write c:\\shure\\shure.exe in the text file.

    I think I should use a FileInputStream and read the file. The string is like String name = "shure";
    and i will put the variable in Process pr = rt.exec(shure + "any-command-for-shure"); ??

    I hope you understand me this time too.
    Last edited by keneid; 06-09-2010 at 02:42 PM.

Similar Threads

  1. Help file for Java commands?
    By tyang in forum New To Java
    Replies: 2
    Last Post: 01-31-2010, 06:09 AM
  2. Replies: 2
    Last Post: 05-11-2009, 10:07 AM
  3. Replies: 0
    Last Post: 02-11-2009, 10:53 AM
  4. Replies: 5
    Last Post: 02-05-2009, 11:28 AM
  5. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 10:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts