Execute several UNIX OS commands from inside Java program

Greetings,
I would like to be able to execute from a Java program several of the following UNIX commands
script filename
cd
date
grep
diff
I have been able to get a single command to work with
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("dir");
My goal here is to accomplish a Java program which will use JDBC to access an Oracle database with SQL and then compare the resultant flat file with a diff command in Unix to another delimited file from an Excel spreadsheet. Your input is appreciated.
Thank you

I would suggeat to use JDBC to get the data from database and then read your file and then use existing java diff program from following link to find the differences between the files
http://www.bmsi.com/java/
I hope this helps
VAN

Similar Messages

  • How to execute unix command from the Java program running on Windows

    Hello,
    I need to
    1. Execute a unix shell script from a Java program running on the Windows.
    2. I also need to capture the output of this shell script in my program.
    Please suggest me how to achieve this.
    Thanks in Advance.

    Hi...
    Something is missing here
    If you want to execute a shell script in windows that not posible unless you find or develop a unix shell script parser for windows.
    But if you are trying the execute a unix shell script on a remote unix computer from your java program running on a windows platform you can do that by logging on to the UNIX terminal which is running on port 23 I think.
    You can test this using telnet tool on windows
    just type on command prompt
    telnet <ip of the unix pc> <port number this case 23>
    you should get the unix terminal. If that works you can do the same through java or you can directly conect to port 23 of that pc using sockets that way your program will be platform independant

  • How:Execute OS commands from a Java program

    hi,
    is it possible to execute an OS command from a java program, as in C/C++? if yes, plz give the details.
    thanx

    In the future try searching the forum before posting. Using keywords like "execute os commands" would lead you to several postings on this topic.
    Note the keywords where taken directly from you subject line. With practice you learn which keywords to use to yield the best search results.

  • Running curl command from a java program using Runtime.getRuntime.exec

    for some reason my curl command does not run when I run it from within my java program and errors out with "https protocol not supported". This same curl command however runs fine from any directory on my red hat linux system.
    To debug the problem, I printed my curl command from the java program before calling Runtime.getRuntime.exec command and then used this o/p to run from the command line and it runs fine.
    I am not using libcurl or anything else, I am running a simple curl command as a command line utility from inside a Java program.
    Any ideas on why this might be happening?

    thanks a lot for your response. The reason why I am using curl is because I need to use certificates and keys to gain access to the internal server. So I use curl "<url> --cert <path to the certificate>" --key "<path to the key>". If you don't mid could you please tell me which version of curl you are using.
    I am using 7.15 in my system.
    Below is the code which errors out.
    public int execCurlCmd(String command)
              String s = null;
              try {
                  // run the Unix "ps -ef" command
                     Process p = Runtime.getRuntime().exec(command);
                     BufferedReader stdInput = new BufferedReader(new
                          InputStreamReader(p.getInputStream()));
                     BufferedReader stdError = new BufferedReader(new
                          InputStreamReader(p.getErrorStream()));
                     // read the output from the command
                     System.out.println("Here is the standard output of the command:\n");
                     while ((s = stdInput.readLine()) != null) {
                         System.out.println(s);
                     // read any errors from the attempted command
                     System.out.println("Here is the standard error of the command (if any):\n");
                     while ((s = stdError.readLine()) != null) {
                         System.out.println(s);
                     return(0);
                 catch (IOException e) {
                     System.out.println("exception happened - here's what I know: ");
                     e.printStackTrace();
                     return(-1);
         }

  • How to run a openssl command from a java program

    Hi All
    Please suggest on how to run a openssl command from a java program.
    I am using this
    Runtime runtime = Runtime.getRuntime();
    runtime.exec("openssl pkcs8 -inform der -nocrypt test.der result.pem");
    This is suppose to take test.der as input and create result.pem.
    There are no errors but the file result.pem isnt created.
    Thanks in Advance

    First off is that openssl command correct? Should it be this instead:
    openssl pkcs8 -inform der -nocrypt -in test.der -out result.pem
    Try out your openssl command within a command prompt so that you know that it works ok. I think the command line you specified waits on stdin (well it does for me).
    After that.....
    runtime.exec creates a Process object. If you do this:
    Process openssl = runtime.exec("....")
    then you can examine the return code from openssl to see the exit code - for instance if the input file does not exist then exit = 1. You can test for this with Java
    Alternatively you could get the stderr from the process and look inside it - if it is 0 length then all is good, if it has some text in there then it has likely failed. You could then throw an exception and include the stderr output in the exception messgae. You may need to experiment with this, runnig it first when openssl is happy then running it again when openssl is upset.
    M

  • How can I pass system commands from a java program? Urgent!

    hi,
    I have been trying this out since a long time. How do I send system commands to command.com or cmd.exe from a java program and an output of the executed command back to the java application.
    If u have any idea, or have any information about the kind os application reply back.
    Thanks
    Deepa Datar

    This is the code which I tried, but it displays only the title of MS-DOS, something like " Microsoft Corp...etc ". But doesn't take any input, and the subprocess(cmd.exe) hangs.
    import java.io.*;
    public class cmddemo2
    public static void main(String arg[])
    try
    System.out.println("cmd");
    Process p=Runtime.getRuntime().exec("cmd.exe");
    DataInputStream din=new DataInputStream(p.getInputStream());
    DataOutputStream dout=new DataOutputStream(p.getOutputStream());
    System.out.println("after streams");
    String s;
    dout.writeChars("type cmddemo2.java");
    while((s=din.readLine())!="\n")
    System.out.println(s);
    dout.writeChars("dir");
    String s1;
    while((s1=din.readLine())!="\n")
    System.out.println(s1);
    System.out.println("over");
    catch(Exception e)
    { System.out.println("Exception : "+e);

  • Calling an unix command from a java program which runs on windows

    Hello All
    I have an Java Application which is run on windows server (I)
    I have another Sun Server (II)
    I want to call an unix command on server(II) from java application which is on server(I)
    I am using Samba Server in order to share files between Windows Server and Unix Server
    Can I use samba in order to call command
    or is there any way to open an telnet session within java application
    I will be grateful if you give me some suggestion on this issue
    Regards
    BEKIR BALCIK
    J2EE Application Developer
    Argela Technologies ...

    cross post
    http://forum.java.sun.com/thread.jspa?threadID=624601&messageID=3553626#3553626

  • How can I execute a batch file from my java program

    Hi,
    Can someone help me or direct me to a link,
    How can I execute a DOS batch file from my java program?
    Thanks

    You will need to grab a handle to the process's
    outputstream so u can see its output.The OP didn't mention any output from any batch file;
    nor any input for that
    matter,so lets not complicate matters here for now
    ok?Actually I think this is essential to see whether it works or not. It's either that or do some manual check to see whether it ran, which is not exactly elegant, and in some cases this may not be easier than simply writing the output stream code, or in fact it may be impossible to check manually.
    I'm sure it wasn't intentional that your post appeared to be bristling with attitude.

  • Efficiently Running UNIX des command from Java

    Hi,
    I am trying to execute the following code in a loop to have an Brute Force attack for recovering the key.
    Runtime r = Runtime.getRuntime();
    p = r.exec("des -D -k "+keys.get(randomIndex)+ " " +cipherTextFileName);
    But as the des command has to read the file every time the programm is not a efficient one.Can I do something like reading the ciphertext from the file only once and then pass it to the des command from the java.So that it won't do I/O operations resulting good performamnce.If I can do this how to do it.Please suggest with examples.
    Thanks
    Tapas

    If you use Java you're not doing that. What does being an Academic project have to do with what tools you're allowed to use? Who is dictating that you're "only" allowed to use the des command line tool? (If it comes to that, which des command line tool are you using anyway? It's not a unix standard thing).
    The one thing you can do is to see if there is an option to read the file(s) from standard input and send them to the process from the Java runtime that way - that way the input doesn't have to be read multiple times. However this is unlikely to make any significant difference. Most of the performance cost is likely to be the context switch required to kick off the new process with very little cost incurred from re-reading a file from the disk cache.
    You've got your answer anyway. You're not going to be able to make this much more efficient. I recommend not doing that. If you really really have to, well, tough.

  • How to execute a unix/dos command in Java

    Hi,
    I want to execute dos/unix commands in my java program. Can anyone tell me how to do this. Say I want to restart my httpd daemon using the command: "service httpd restart" or test my httpd.conf file using the command "testparn"
    thanks in advance
    Hugo Hendriks

    hallo,
    test this:
    Process p = Runtime.getRuntime().exec(Your_Programm);
    p.waitFor();
    LineNumberReader lnr = new LineNumberReader(new InputStreamReader(p.getInputStream()));
    Your_Programm must be a shellscript. regard that your java programm must have the right to start the httpd!
    Carsten Bluetner

  • How to execute solaris lpd printing command from java code

    hi folk,
    I want to print a post script file on a network printer (my java code will receive the Printer's IP Address and the filename ) , i'm using the solaris lpd printing command :
    lpadmin -p banana_ps -o protocol=bsd,dest=IP -v /dev/null
    -m netstandard -T PS -I postscript
    my question is how execute this command from the java code :)
    i really appreciate ur advices

    Hi,
    See RunTime.getRuntime ().exec (...).
    Hope that help,
    Jack

  • Can we execute DOS Commands from a Java Application

    I just want to know whether we can execute DOS Commands from a Java Application.
    Thanks.

    hi,
    try this:
    Runtime.getRuntime().exec("cmd /c start abc.bat");
    andi

  • Need to execute tcl script from a Java Program

    Hello,
    I need to execute a tcl script from a Java Program. But I do not know how to call the tcl Interpreter. Can anybody help me?

    Iam using the exec command as follows:
    Process proc =
    rt.exec("C:/SpirentConnect/engines/tcl/8.3.4/windows/s
    ctcl.exe C:/Hello.tcl");
    But Hello.tcl is not executed.And does that exact string work on the command line?
    And what is the return code from running it?

  • Execute a unix shell script from forms9i

    Hi ,
    I would like to execute a unix shell script form a form when they pressed a button. The forms server is on Linux machine. I tried but when I pressed the button nothings happen. Could some one please help me how I could get working.
    Is there is a way I could execute the unix shell script from PL/SQL proceudre or package.
    Please some one help me.
    Bain

    You would not expect to see anything happening because the
    script cannot directly send output to the web form. However, you can get it to write output to a file and use web.show_document in the form after the host command to display the file and see the output.

  • Running a Linux command "clear" from a Java program

    Hello. How to run a simple linux command to clear the screen from a Java program. I did the following
    Process p = Runtime.getRuntime().exec("clear");
    Nothing is happening.

    you're not supposed to mess with the shell, youdon't own it and
    shouldn't try to dictate what happens with it.
    The shell is a multiuser system,What?
    The command shell (for example sh, ksh, bash, csh,
    zsh) is a process, a command interpeter just like any
    other (user mode) program.
    yes, and there can be multiple processes writing to it at any one time.
    You do NOT have exclusive access to it, nor should you ever assume you do.
    In a multiuser system there can be several shells
    running on behalf of several users. The same user can
    run several shells.
    Yes, and each shell can be accessed by multiple processes at any one time.
    So what?
    Process a writes to the shell.
    Process b writes to the shell.
    Process a clears the shell, removing whatever process b wrote there.
    You've just messed up process b, or at the very least its output.
    Do NOT assume you have exclusive access to any shell.

Maybe you are looking for

  • Switching to FCE

    I use iMovie HD for my lecture/sermon videos. Each video is approximately 1.5 hours in length, 22 total tapes. When I get home, I load into computer. Total of 33 hours to load, let alone the editing etc. For this reason I'm looking into a hard drive

  • Logi Report with SAP

    Hi All, Can we use product 'Logi Report' or any other Reporting tool other than 'Crystal Reports'? Crystal reports seems expensive and that for its procurement, SAP Integration toolkit is to be procured separately. What do you people suggest? Regards

  • VEPVG table problem

    Hi experts, The requirement is to avoid to dissapearing sales orders items in VL10 after delivered quantity = max (no open quantity is accessible)... The thing is that system takes items from VEPVG table and check open quantity (VEPVG-BRGEW). This fi

  • Session tracing with HttpSessionBindingListener

    Hi, I hope someone can help. I am an Oracle developer/ assis,. dba looking at the possiblilties of Servlet and JSP's as front end apps for my databases. I'm trying to call an event when a session invalidates but i am having great difficulty whith get

  • Camileo X100 freezes using remote at the end of clip

    I bought a Toshiba Camileo X100 a few days ago. The camera is great, I like it very much. However, there is a problem with the firmware I think. The remote control is functioning, as expected, although there is no detail about its usage in the manual