Calling an executable from a java program

How can I call a compiled program from a java program. I have a fortran program, which I would like to call for execution from within my java program. My OS is linux.
Thanks,
An

Not quite sure in the case of fortran program, but one thing can be done, call ur fortran program from a batch (.bat file) and call this .bat file from java ;
try {
Process p = Runtime.getRuntime().exec("run.bat");
p.waitFor();
catch( Exception e ) {
}

Similar Messages

  • Possibility of calling standard actions from a java program

    Hi ,
    I am working for a project where customer wants to have option of saving orders as draft only and later convert to order if need be. However since we do not want many drafts to reside on server there is a need to delete these at a specified time. For draft orders I am using order templates since they stay in the database without getting converted to orders. Now I do not know how to go about the deletion part.
    i need to write a program that would run on the server and which would fetch the templates (drafts) that have been created till a particular time and call the delete action of the template. Now the question is how do i call these actions from a java program where this java program will have to run on the server end (ie will be a backend process).
    Please suggest.
    Thanks
    Roopali

    hello roopali,
    you can create a separate thread that will run your
    code that will check for stale drafts and delete them.
    it is just like a session management program but here
    we will be looking over the drafts and not the session
    objects.
    now if you want the invocation of the action from another
    program, a socket program would suffice but opening ports
    will cause you network connections thru firewall.
    if you can make use of HTTP servlet as your service
    provider e.g., you can then just pass some action params
    to invoke it.
    regards
    jo

  • Calling OCX Methods from a Java Program

    Hi All,
    Is it possible to call OCX methods from a Java program? If yes, can you please refer me to any documents or sample code to achieve this.
    All inputs are highly appreciated.
    Thanks
    Tarek

    JNI
    http://java.sun.com/docs/books/tutorial/native1.1/index.html

  • Calling jsp page from a java program

    Hello,
    Is it possible to call a JSP page from a java program? If so, please let me know how it is possible.
    I have a JSP page that inserts 10 records in a database based on the attribute given to the page. When the java program is executed all the 10 records need to be inserted.
    The JSP page is already running fine in Tomcat.
    Thanks and Regards,
    Prasanna.

    MVC has applied the standard of seperate your view , model and controller. I believe nobody will insert data from jsp page,better practice should be inserted from your database layer, normally is like DAO layer. so you should pass your data from jsp to your backend.
    hopefully it's help u

  • Calling another application from a java program

    Hi, Java ppl.
    I wanted to know how can I call another program say a help application or an exe from a java program. anyone with any advice or a piece of code would help.
    Thanks
    Pradeep

    I had the same situation and I tried the code that you sugested and it works. I was wondering, what am I expecting in the while loop that appears after the int inp; statement? Is some data going to be displayed on the screen? How essential is to have that while loop after the calling the exec() method?
    Sorry for the amount of questions, I never tried this before.
    Best regards,
    Luis E.

  • Calling a servlet from a java program

    I could not find a forum for servlet hence am posting
    here
    I have a servlet that accepts prameters and
    gives some out put .
    I want to be able to call this servlet ( invoke )
    from a Java Program .
    How do i do that ..
    Any sample code /pointer would be appreciated.
    Deepa

    hi
    you can try this code.
    URL url = new URL("http://localhost:8888/yourServlet?param1=value1");
    URLConnection con = url.openConnection();
    StringBuffer sBuf = new StringBuffer();
    BufferedReader bReader = new BufferedReader(
    new InputStreamReader(
    con.getInputStream()));
    String line = null;
    while((line = bReader.readLine()) != null) {
    sBuf.append(line);
    System.out.println(sBuf);
    hope this helps
    Shrini

  • How to launch executable from a java program

    In c++ we can use a function WinExec to execute exe from a c++ program.
    Is there a way to launch executables using java program. Lets say I have one executable with name "myexecutable.exe" and a java program "myprogram.java". How can I launch "myexecutable.exe" from the java program.
    Is there a way to do this in Java?
    Vijay

    >>
    class LoadExecutable
    static void loadProcess()
    Runtime r = Runtime.getRuntime();
    Process p = r.exex("winword.exe");
    public static void main(String args[])
    loadProcess();
    }Regards
    - ManikantanBoth of these aren't good ideas - neither of them
    deals with the input or output streams at all.
    Everyone who's posted to this thread should read this.
    None of you knows how to use Runtime.exec properly:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-t
    aps.html
    MOD
    Thanks for the tips
    -Regards
    Manikantan

  • Call ODI Scenario from a Java Program

    Hi,
    I would like to invoke the ODI Scenario from a Java Program. Is there any way i can do this?
    Please let me know if you have any posts related to this.
    Thanks,
    Mansur

    Check this ..
    How to run ODI scenario from java?

  • Calling another class from a java program

    I tried to call the Server1.class from the password program, but I failed. The password program source code is as follows:
    class PasswordDialog extends java.awt.Dialog implements java.awt.event.ActionListener
         * Constructor. Create this visual dialog component.
         public PasswordDialog(java.awt.Frame parent, PasswordVerifier verifier)
              super(parent);
              addWindowListener(new WindowEventHandler());
              setLayout(new java.awt.FlowLayout());
              setSize(500, 100);
              this.verifier = verifier;
              add(useridField = new java.awt.TextField(10));
              add(passwordField = new java.awt.TextField(10));
              add(okButton = new java.awt.Button("Submit"));
              add(cancelButton = new java.awt.Button("Cancel"));
              okButton.addActionListener(this);
              cancelButton.addActionListener(this);
              passwordField.setEchoChar('*');
              useridField.requestFocus();
         public void actionPerformed(java.awt.event.ActionEvent e)
              if (e.getSource() == okButton)
                   // Invoke password verification callback
                   try
                        boolean result = verifier.verifyPassword(
                             useridField.getText(), passwordField.getText());
                        if (! result) return;     // verification failed; don't close this dialog
                   catch (Exception ex)
                        ex.printStackTrace();
                   // Close this dialog
                   System.out.println("I still can't call the Server1 class");
                   dispose();
              else if (e.getSource() == cancelButton)
                   dispose();
         class WindowEventHandler extends java.awt.event.WindowAdapter
              public void windowClosing(java.awt.event.WindowEvent e)
                   System.exit(0);
         // Private objects
         private PasswordVerifier verifier;
         private java.awt.TextField useridField;
         private java.awt.TextField passwordField;
         private java.awt.Button okButton;
         private java.awt.Button cancelButton;
    interface PasswordVerifier
         public boolean verifyPassword(String userid, String password) throws Exception;
    public class password implements PasswordVerifier
         * Main routine for testing only.
         public static void main(String[] args)
              password verifier = new password();
              java.awt.Frame f = new java.awt.Frame("Password Verifier");
              f.setSize(100, 100);
              f.show();
              PasswordDialog d = new PasswordDialog(f, verifier);
              d.show();
         public boolean verifyPassword(String userid, String password) throws Exception
              return (userid.equals("Albert") && password.equals("Einstein"));
    and the Server1.java is as follows:
    //Server Application
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    public class Server1 extends Frame implements ActionListener,Runnable,KeyListener
    ServerSocket s;
    Socket s1;
    BufferedReader br;
    BufferedWriter bw;
    TextField text;
    TextField name;
    Button exit,clear;
    Label label;
    List list;
    Panel p1=null;
    Panel p2=null;
    Panel sp21=null;
    Panel sp22=null;
    Panel jp=null;
    public void run()
              try{s1.setSoTimeout(1);}catch(Exception e){}
              while (true)
                   try{
    list.add(br.readLine());
                   }catch (Exception h){}
    if(list.getItemCount()==7)
    list.remove(0);
    public Server1(String m)
    {       super(m);
    jp=new Panel();
    p1=new Panel();
    p2=new Panel();
    sp21=new Panel();
    sp22=new Panel();
    jp.setLayout(new GridLayout(2,1));
    p1.setLayout(new GridLayout(1,1));
    p2.setLayout(new GridLayout(2,1));
    sp21.setLayout(new FlowLayout());
    sp22.setLayout(new FlowLayout());
    exit = new Button("Exit");
    clear = new Button("Clear");
    exit.addActionListener(this);
    clear.addActionListener(this);
    list = new List(50);
    text = new TextField(43);
    name = new TextField(10);
    label = new Label("Enter your name");
    name.addKeyListener(this);
    text.addKeyListener(this);
    p1.add(list);
    sp21.add(text);
    sp21.add(exit);
    sp22.add(label);
    sp22.add(name);
    sp22.add(clear);
    p2.add(sp21);
    p2.add(sp22);
    jp.add(p1);
    jp.add(p2);
    this.add(jp);
    setBackground(Color.orange);
    setSize(380,300);
    setLocation(0,0);
    setVisible(true);
    setResizable(false);
    name.requestFocus();
    try{
    s = new ServerSocket(786);
                   s1=s.accept();
                   br = new BufferedReader(new InputStreamReader(
                             s1.getInputStream()));
                   bw = new BufferedWriter(new OutputStreamWriter(
                             s1.getOutputStream()));
    bw.write("Welcome");bw.newLine();bw.flush();
                   Thread th;
                   th = new Thread(this);
                   th.start();
              }catch(Exception e){}
    public static void main(String args[])
    new Server1("Server");
         public void actionPerformed ( ActionEvent e)
    if (e.getSource().equals(exit))
                   System.exit(0);
    else if (e.getSource().equals(clear))
    { name.setText(" ");
    name.setEditable(true);
    public void keyPressed(KeyEvent ke) {
    if(text.equals(ke.getSource()))
    if(ke.getKeyCode()==KeyEvent.VK_ENTER)
    try{
    bw.write(name.getText()+">>"+text.getText());
                   bw.newLine();bw.flush();
                   }catch(Exception m){}
    list.add(name.getText()+">>"+text.getText());
    text.setText("");
    else if(name.equals(ke.getSource())) {
    if(ke.getKeyCode()==KeyEvent.VK_ENTER)
    name.setEditable(false);
    text.requestFocus();
    public void keyReleased(KeyEvent ke)
    //something
    public void keyTyped(KeyEvent ke)
    //something
    I tried to create a new object by typing:
    Server1 s = new Server1();
    then call the main function
    new Server1("Server");
    but it doesn't work. Anybody can help me with this?

    try
    Server1 s = new Server1();
    s.Server1("Server");
    or
    new Server1().Server1("Server");

  • 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

  • Cannot call ANY stored functions from my Java program

    My problem is that I cannot call ANY stored procedure from my Java
    program. Here is the code for one of my stored procedures which runs
    very well in PL/SQL:
    PL/SQL code:
    CREATE OR REPLACE PACKAGE types AS
    TYPE cursorType IS REF CURSOR;
    END;
    CREATE OR REPLACE FUNCTION list_recs (id IN NUMBER)
    RETURN types.cursorType IS tracks_cursor types.cursorType;
    BEGIN
    OPEN tracks_cursor FOR
    SELECT * FROM accounts1
    WHERE id = row_number;
    RETURN tracks_cursor;
    END;
    variable c refcursor
    exec :c := list_recs(11)
    SQL> print c
    COLUMN1 A1 ROW_NUMBER
    rec_11 jacob 11
    rec_12 jacob 11
    rec_13 jacob 11
    rec_14 jacob 11
    rec_15 jacob 11
    Here is my Java code:
    import java.sql.*;
    import java.io.*;
    import oracle.jdbc.driver.*;
    class list_recs
    public static void main(String args[]) throws SQLException,
    IOException
    String query;
    CallableStatement cstmt = null;
    ResultSet cursor;
    // input parameters for the stored function
    String user_name = "jacob";
    // user name and password
    String user = "jnikom";
    String pass = "jnikom";
    DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    try { Class.forName ("oracle.jdbc.driver.OracleDriver"); }
    catch (ClassNotFoundException e)
    { System.out.println("Could not load driver"); }
    Connection conn =
    DriverManager.getConnection (
    "jdbc:oracle:thin:@10.52.0.25:1521:bosdev",user,pass);
    try
    String sql = "{ ? = call list_recs(?) }";
    cstmt = conn.prepareCall(sql);
    // Use OracleTypes.CURSOR as the OUT parameter type
    cstmt.registerOutParameter(1, OracleTypes.CURSOR);
    String id = "11";
    cstmt.setInt(2, Integer.parseInt(id));
    // Execute the function and get the return object from the call
    cstmt.executeQuery();
    ResultSet rset = (ResultSet) cstmt.getObject(1);
    while (rset.next())
    System.out.print(rset.getString(1) + " ");
    System.out.print(rset.getString(2) + " ");
    System.out.println(rset.getString(3) + " ");
    catch (SQLException e)
    System.out.println("Could not call stored function");
    e.printStackTrace();
    return;
    finally
    cstmt.close();
    conn.close();
    System.out.println("Stored function was called");
    Here is how I run it, using Win2K and Oracle9 on Solaris:
    C:\Jacob\Work\Java\Test\Vaultus\Oracle9i\FunctionReturnsResultset>java
    list_recs
    Could not call stored function
    java.sql.SQLException: ORA-00600: internal error code, arguments:
    [ttcgcshnd-1], [0], [], [], [], [], [], []
    at
    oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
    at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
    at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
    at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1405)
    at oracle.jdbc.ttc7.TTC7Protocol.fetch(TTC7Protocol.java:889)
    at
    oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:490)
    at
    oracle.jdbc.driver.OracleStatement.getCursorValue(OracleStatement.java:2661)
    at
    oracle.jdbc.driver.OracleStatement.getObjectValue(OracleStatement.java:4189)
    at
    oracle.jdbc.driver.OracleStatement.getObjectValue(OracleStatement.java:4123)
    at
    oracle.jdbc.driver.OracleCallableStatement.getObject(OracleCallableStatement.java:541)
    at list_recs.main(list_recs.java:42)
    C:\Jacob\Work\Java\Test\Vaultus\Oracle9i\FunctionReturnsResultset>
    Any help is greatly appreciated,
    Jacob Nikom

    Thank you for your suggestion.
    I tried it, but got the same result. I think the difference in the syntax is due to the Oracle versus SQL92 standard
    conformance. Your statament is the Oracle version and mine is the SQL92. I think both statements are acceptable
    by the Oracle.
    Regards,
    Jacob Nikom

  • 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?

  • Executing a stored procedure from a java program

    Hi.. how can i call a oracle stored procedure from a java
    program. the OSP has four IN parameters and one OUT parameter(a
    cursor). when i try this way.. i get an error
    con = DriverManager.getConnection(url, "stored", "stored");
    CallableStatement cs =
    con.prepareCall(
    "{call stored_proce_1(?,?,?,?,?)}");
    cs.registerOutParameter(1, OracleTypes.CURSOR);
    cs.setString(2, "14541");
    cs.setString(3, "gen");
    cs.setInt(4, 0);
    cs.setInt(5, 5);
    ResultSet rs =cs.getResultSet();
    while(rs.next()){
    System.out.println(rs);
    appreciate ur help.
    qs

    I'm no expert on this, but I have a similar call where I fetch
    an Oracle REF CURSOR from a call to a stored function. If you
    fetch the cursor as an Object from your CallableStatement, you
    can then cast it to a ResultSet e.g.
    mystatement.executeUpdate();
    ResultSet rs = (ResultSet) mystatement.getObject(1);
    Then you should be able to loop through your ResultSet as usual.
    Good luck!
    Chris

  • 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 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.

Maybe you are looking for