Running COBOL programs from java

I am on a project at the moment where we want the client-server to be written in Java on Solaris Sparc UNIX machines. The thing is we want the server to start a COBOL program and the output from the COBOL program will be the reply to the client. Is this possible and if so how?
Any help gratefully received
Chris
PS We are not looking to buy expensive tools

JNI would be necesssary if you want to call cobol routines from your java program or vice versa. If you want to communicate with another process then JNI is not really necessary. Indeed it is a very difficult API to master and unnecessary complexity. Well the way I was thinking was that your cobol program can accept input from standard input and write to standard output (if there is such a thing in cobol). You can then read the inputstream of the process which you spawned using runtime.getRuntime.exec("mycobolprogram) mechanism...This should work fairly realiably. I am not sure if this is what you are looking for but give it a try by writing a small cobol program which outputs "Hello World" to standard output and then try reading it from a test java program...

Similar Messages

  • Run a program from java code

    I want to run this program from my java code,
    In Linux(ubuntu) I write this command to open the program window
    $ paraFoam -case /home/saud/OpenFOAM/OpenFOAM-1.5/run/tutorials/icoFoam/cavity/In my java code I wrote it like this("/home/saud/OpenFOAM/OpenFOAM-1.5/bin/" is the path of the program):
    String command = "/home/saud/OpenFOAM/OpenFOAM-1.5/bin/paraFoam " +
              "-case /home/saud/OpenFOAM/OpenFOAM-1.5/run/tutorials/icoFoam/cavity/";
    final Process myProcess = Runtime.getRuntime().exec(command);
    BufferedReader buf = new BufferedReader(new InputStreamReader(
              myProcess.getInputStream()));
    String line;
    while ((line = buf.readLine()) != null) {
         System.out.print(String.format("%s\t\n", line));
    buf.close();
    int returnCode = myProcess.waitFor();
    System.out.println("Return code = " + returnCode); Return code = 0
    but the program is not opening
    Edited by: Saud.R on Apr 11, 2009 3:37 AM

    Welcome to the Sun forums.
    I am not sure of the answer to your question, but people who use Processes regularly, warn other users to ensure they are also doing something with the error stream of the process, otherwise it can hang as you describe.

  • Running a program from Java

    how do i launch one Java program from another?
    both .class files and the JRE directory are in the same directory

    You can use Runtime.exec() to run it as a seperate process, or you can always instantiate your secondary class. Do a search on the term "runtime.exec()" befure you go spawning another thread asking how to use it. That particular subject has been done to death many times already.

  • Problems running external programs from java

    Hello.
    I wrote a pair of perl scripts and a GUI in java to run them. The first perl script just read the files in one directory makes some changes to the names of the files and then group all this files in a set of new directories. The other perl scripts takes all this new files and calls BLAST sequence alignment program and perform some alignments among these sequences. I tested this scripts and they work fine.
    The problem comes when I try to run them for the JAVA GUI. I use RunTime and when I need to run the first perl script it all works well, but when The call to the second perl script is made the program fisishes without doing anything at all. I found out that the problem is that when running the script from the Java GUI it's not able to find BLAST program. So I guess that Java is not really starting a terminal session and it doesn't read my bash_profile to find out the path to my programs.
    So, my question is if anyone knows a method to tell Java to load all this paths in the bash_proflie file so all of my scripts work???.
    I have no idea is this can be done and how so any advice would be really wellcome.
    By the way, my java version is 1.4.2 and my OS is Mac OS X 10.3
    Thanks a lot , Julio

    Invoke /bin/sh -c and give it your program's full path with.
    (To understand what I've written, maybe reading
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps_p.html
    http://mindprod.com/jgloss/exec.html
    and
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
    (especially the exec(String[] cmdarray) method)
    might help)
    -T-

  • Starting Cobol program from JAVA

    Hi
    For a school project we have to do a part Java & a part cobol
    The COBOL programmes are all to read CSV files into an MS access DB
    Well as a challenge we have to make a buton in the GUI of our JAVA program that starts 1 of these COBOL programes when clicked
    The java program was written/modelled in Together Architect 2006 (eclipse plugin, sry the school forces us to use it) and the COBOL were/are written in percobol from legacyJ
    txn for any help

    i've done that but i seem to not getting the hang of
    it
    from what i get is it something like thhis
    runetime.getRuntime().exec("myCobolprog.cbl");
    yet it doesnt seem to work
    or i just get errors in the IORead this first:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Run a program from java

    hi
    i have a program with extension .rcw and i want to run from a java program. can anyone show me the code that can help me to call this type of files or any type of files
    Thanks in advance.

    **  Here is a pure Windows solution
    **  Run the code and you will be taken to a tutorial
    that may provide
    **  a more generic solution
    public class WindowsProcess
         public static void main(String[] args)
              throws Exception
              String[] cmd = new String[4];
              cmd[0] = "cmd.exe";
              cmd[1] = "/C";
              cmd[2] = "start";
    cmd[3] =
    =
    "http://www.javaworld.com/javaworld/javatips/jw-javati
    p66.html";
    //          cmd[3] = "notepad";
    //          cmd[3] = "will.xls";
    //          cmd[2] = "a.html";
    //          cmd[3] = "file:/c:/java/temp/a.html";
    Process process = Runtime.getRuntime().exec( cmd
    md );
    }i really don't know what to say. You really help me.
    I'm really thankfull to you

  • Cannot run batch program from Java Application

    Hi All,
    Im trying to run a batch file under windows from my Java Program. The batch file is located in the following path:
    C:\Program Files\MyApp\runme.bat
    The above-entioned path contains white space which is not allowed in NT.
    Im trying following code:
    import java.io.*;
    public class Exec {
    public static void main(String args) {
    try {
    Runtime.getRuntime().exec("cmd /c start C:/Program Files/MyApp/runme.bat");
    }catch(Exception ex){ ex.printStackTrace();}
    How to run this file?
    Thanks in advance.
    Ketan Malekar

    or use the overload that takes an array of strings as argument
    String[] command = {"cmd", "/c", "start", "C:/Program Files/MyApp/runme.bat");
    Runtime.getRuntime().exec(command);

  • Running DOS program from java

    Hi all,
    I'm trying to execute a dos program using:
    runtime.exec("dos_prog.exe")
    THE PROBLEM : in this way I can run only
    WINDOWS programs and NOT DOS progs.
    What to do ???

    Hi all!
    I'm tring to run a file.bat that execute an exp from locale Oracle server. But when I run it, in dos consol it appaire just only the EXP USER/PASS ....., and don't execute never!! Really, the files of .dmp and of .log, they are created, ...but empty!!!! Why???
    ........ source .......
    Runtime rt = Runtime.getRuntime();
    Process rtProcess = rt.exec("cmd.exe /C file.bat");
    // wait for command to terminate
    try      {
         rtProcess.waitFor();
    catch     (InterruptedException ire)
         System.err.println("Thread interrupted " + ire.getMessage());
    // check its exit value
    if (rtProcess.exitValue() != 0)
    System.err.println("exit value was non-zero");
    // close stream
    bReader.close();
    ........ file.bat .......
    @echo off
    EXP USER/PSW FILE=EXPFILE.DMP LOG=FILELOG.LOG OWNER=MYOWNER
    If you want, you car reply me directly at [email protected] - Thanks very much!!!

  • Running another program from Java on OSX

    I have an application that allows the user to specify an external program to run using the Process class, they just have to xpecify the path.
    On OSX most of the apps are in .app packages with the contents hidden to the filechooser. What command do I need to run to start (for example ITunes) an application

    Thanks, this is very wierd but compard to other OSes seems to work

  • How to run native program with Java program?

    Hello
    I've got following problem. I'd like to write file browser which would work for Linux and
    Windows. Most of this program would be independent of the system but running programs not. How to run Linux program from Java program (or applet) and how to do it in Windows?.
    Cheers

    Try this:
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("ls -l");
    InputStream stream = proc.getInputStream();
    InputStreamReader isr = new InputStreamReader(stream);
    BufferedReader br = new BufferedReader(isr);
    String line = null;
    while ( (line = br.readLine()) != null) .....
    "if the program you launch produces output or expects input, ensure that you process the input and output streams" (http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html)

  • Call visual prolog program from java

    Hi friends,
    is there someone help me to call ( run) prolog program from java.
    i write a parser with Javacc parser generator and stored parsed information in prolog database and I want create some query in java that work in the prolog file.
    how can i combine java and prolog programs. i used visual prolog.
    Can someone help me?
    Thanks you in advance.
    yours sincerely,
    ksu

    Since visual prolog can produce dll's, you can use JNI:
    http://java.sun.com/j2se/1.4.2/docs/guide/jni/index.html

  • Can we run EXE file/ Another Java Program from Java Application? How?

    Can we run EXE file and another java program from java application?
    Thanks in advance

    Example running adobe acrobat
    String command = "C:\\Program Files\\Adobe\\Acrobat 5.0\\Reader\\AcroRd32.exe /t "+selectedDocument+" \\\\CONTROL\\HP LaserJet 4L";
    Runtime rn = Runtime.getRuntime();
    Process process = rn.exec(command);
    process.waitFor();rykk

  • Running ls command from Java stroed procedure no output

    Hi ,
    I am trying to run ls command from java stored procedure in oracle
    Process p = Runtime.getRuntime().exec("ls");
    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("output of the command run:\n");
    while ((s = stdInput.readLine()) != null) {
    System.out.println(s);
    from java stored procedure in oracle.
    i get output of println statments but it does not go into while loop to print from stdInput.
    Result of running Java stored procedure is -
    output of the command run:
    Call completed.
    when i run the program on client side it works fine.
    Has anybody tried this from java stroed procedure.
    Thanks,
    Jag

    Jag,
    Actually, the question of whether it works for me seems to depend on the version of the OS (or Oracle). On RedHat Linux (Oracle 8.1.6) it didn't work at all, but on Solaris (Oracle 9.0.2) it did. Here's the output from that run:
    SQL> /
    output of the command run:
    init.ora
    initDBPart9i.DBPSun01.ora
    initdw.ora
    lkDBPART9I
    orapw
    orapwDBPart9i
    spfileDBPart9i.ora
    Done
    PL/SQL procedure successfully completed.
    But, I did need to change a line of your code to this:
    Process p = Runtime.getRuntime().exec("/usr/bin/ls");
    your original was:
    Process p = Runtime.getRuntime().exec("ls");
    You might consider, if possible, use of some of the Java File classes instead of ls, as this might make things more predictable for you. There were some examples in oramag.com a few months ago, but they were pretty simple (you might not need them).
    Hope this helps,
    -Dan
    http://www.compuware.com/products/devpartner/db/oracle_debug.htm
    Debug PL/SQL and Java in the Oracle Database

  • How do I call a C++ program from Java?

    I've tried using Runtime.exec to call my C++ program from Java but I don't think I'm doing it correctly. Could someone explain how to properly use it? Here's what I'm trying (this is in an applet that is only going to be running on an intranet so only PCs in my LAN will be affected):
    Runtime runtime=runtime.getRuntime();
    Process proc =runtime.exec("mkdir C:\\Test");

    What do you expect your operating system should do with a command "mkdir"? It doesn't understand this. "mkdir" is a shell command, so you need to execute the shell:
    runtime.exec("cmd /c mkdir C:\\test");

  • Running .EXE file from Java

    Do you know, how run an .exe file, for example Internet Explorer or other program, from Java application?
    It's very important for me.

    Too run external program and pass string arguments see class java doc
    of java.lang.Runtime method exec . You see online or download or
    rename src.jar to s.zip EXTRACT and see
    exec
    public Process exec(String[] cmdarray,
    String[] envp)
    throws IOException
    Executes the specified command and arguments in a separate process with the
    specified environment.
    This is a convenience method. An invocation of the form exec(cmdarray, envp)
    behaves in exactly the same way as the invocation exec(cmdarray, envp,
    null).
    Parameters:
    cmdarray - array containing the command to call and its arguments.
    envp - array of strings, each element of which has environment variable
    settings in the format name=value, or null if the subprocess should inherit
    the environment of the current process.
    Returns:
    A new Process object for managing the subprocess
    Throws:
    SecurityException - If a security manager exists and its checkExec method
    doesn't allow creation of the subprocess
    IOException - If an I/O error occurs
    NullPointerException - If cmdarray is null, or one of the elements of
    cmdarray is null, or one of the elements of envp is null
    IndexOutOfBoundsException - If cmdarray is an empty array (has length 0)
    See Also:
    ProcessBuilder
    getRuntime
    public static Runtime getRuntime()
    Returns the runtime object associated with the current Java application.
    Most of the methods of class Runtime are instance methods and must be
    invoked with respect to the current runtime object.
    Returns:
    the Runtime object associated with the current Java application.

Maybe you are looking for

  • An error occured while getting a portlet instance

    Hello all I am trying to deploy and test accessing tn3270 portlet found here http://www.oracle.com/technology/products/ias/portal/point/tn3270/installation.html using Jdev 10.1.3.3 with preconfigured OC4J deployed the portlet to preconfigured OC4J an

  • Line break in UWL

    Hi All, I have a workflow which gives a workitem in the UWL. I display few variables in the workitem in UWL. All the values in the variables are fine. But the problem is all the variables are coming as continuous text without line breaks. I have give

  • In which file discoverer connections stored

    hi, When we create a connection in discoverer using discoverer/plus url, in which file all these connections are stored and how to delete a connection. Fyi, I am talking about Oracle 9ias. Regards Kumar

  • Contolling drop down for a field in table controll.

    Can we controll the drop down of a field in a table controll ..which will vary from one row to another. Like for one row that field shud have add, delete in drop down, and for another row it shud hav only replace in the drop down

  • Spell checker help, PLEASE

    I have a MacBook Pro Unibody with OSX 10.6.8, and my spell checking system went away.  I also have cocoAspell 2.1 installed too. Neither one is working. I'm not sure what I'm doing wrong, but what I REALLY LIKES was having all of my misspelled words