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");

Similar Messages

  • How to Call abap functn/program from java layer

    Hi all,
        I have to develop a program which has to call abap function/program from java side or how to call a abap program through java ..
    pls send me related links or explanations.. dont send unrelated answers..
    Regards,
    Arivarasu S

    Hi,
    You mean accessing ABAP functions from J2EE perspective, then I think we can do this by using SAP Java Resource Adapter and also through webservices.
    SAP Java Resource Adapter (SAP JRA) can be used as an add-on for the SAP JCo SAP JRA enables the implementation of standard interfaces from diverse J2EE servers to the SAP JCo in the SAP Web AS. The SAP JRA thus simplifies
    communication with ABAP within heterogeneous J2EE landscapes.
    Go through the following links which has Good documentation on how to achieve this
    Accessing BAPIs Using the SAP Java Resource Adapter
    [https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/ad09cd07-0a01-0010-93a9-933e247d3ba4]
    Connectivity and Interoperability
    [https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/326d82e5-0601-0010-fca4-9caf27b89c26]
    Finally with WebServices. Accessing SAP Business Functions (ABAP) via Web Services
    [https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/06adbf03-0a01-0010-f386-d8e45561a3c4]
    Regards
    Raghu

  • How can i call forpro prg file from java

    Hai friends,
    I have a doubt,clear it.
    how can i call forpro prg file from java file
    by,
    N.Vijay

    Thanks to your reply,
    I have some print statements in my foxpro program file.
    Then i like to invoke that foxpro file from my java file
    This want i want..,
    by,
    N.Vijay

  • 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

  • How can I call a hsqldb procedure from Java

    Hello,
    I am trying to call from Java a stored procedure but I keep having exceptions!!!
    In addition, I have no idea how I can get the result of the procedure !!!!
    I have spent the whole day in Internet.... no luck!!
    ===============================================
    I[b] java.lang.Exception: +updatejava.sql.SQLException: Unexpected token: # in statement [ call MODIFY_FIELD_SEPARATOR(#) ]
         at util.UtilBean.test_upd(UtilBean.java:369)
    ===============================================
    The following procedures have been created and tested withing the database and there work.
    - public static String manage_field_separator(String ifs)
    -public static String manage_refresh_interval(int val)
    The alias have been created:
    CREATE ALIAS MODIFY_FIELD_SEPARATOR FOR "com.lucent.util.StoredProcedures.manage_field_separator";
    CREATE ALIAS MODIFY_REFRESH_INTERVAL FOR "com.lucent.util.StoredProcedures.manage_frefresh_interval
    My file.java contains the flollowing:
    public String test_upd(String tableName, String paramValue)
                                         throws Exception
       String res="0";
       Connection conn=null;
       CallableStatement cs= null;
        try
          conn=DBConnection.DBConnect();
          String p="MODIFY_"+tableName.toUpperCase()+"("+paramValue+")";
          cs=conn.prepareCall( "{call "+p+"}");
         cs.execute();
           // Suppose to get the result res  of the function!!!!
        catch (SQLException e)
         exceptionMessage="+update"+e.toString();
         System.out.println("exceptionMessage="+exceptionMessage);
         throw new Exception(exceptionMessage);
        finally
          Statement stmt=null;
          DBConnection.closeConnection(conn,stmt);
        return res;
      }Obviously I am doing something wrong ..... but I don't know what!!!
    Could you help me please?
    THanks a lot!

    Thanks for your quick response.
    I need to construct the name of the procedure on the fly because I don't know the name of the table I need to modify until excecution time.
    I have modified the code the following way but it still does not work!!!
    I still get the exception:
    java.lang.Exception: +updatejava.sql.SQLException: Unexpected token CALL, requires SELECT in statement [(call MODIFY_FIELD_SEPARATOR(?)}]
         at util.UtilBean.test_upd(UtilBean.java:380)
    public String test_upd(String tableName, String paramValue)
                                         throws Exception
       String res="0";
       Connection conn=null;
       CallableStatement cs= null;
        try
          conn=DBConnection.DBConnect();
          cs=conn.prepareCall( "(call MODIFY_"+tableName.toUpperCase()+"(?)}");
         cs.setString( 1, paramValue);
         cs.execute();
           // Suppose to get the result res  of the function!!!!
        catch (SQLException e)
         exceptionMessage="+update"+e.toString();
         System.out.println("exceptionMessage="+exceptionMessage);
         throw new Exception(exceptionMessage);
        finally
          Statement stmt=null;
          DBConnection.closeConnection(conn,stmt);
        return res;
      }

  • Calling a C program from Java

    is there a way we can supply those command arguments when say we click a button, and the command argument is somthing like
    "server test.txt output.txt"
    where server is an executable ".exe" written in C and test.txt is the input file while output.txt is the output file..
    bottom line... can java call a C program within a GUI ??
    is that possible?
    is it the only way through: Runtime.exec() ?
    thank you very much

    my c program is an exe..
    i tried to execute the program using runtime.exec but faced problem..please help..
    im using the StreamGobbler from: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    try
    String fileinputstring = "./outputfile/input.dat";
    FileInputStream fis = new FileInputStream(fileinputstring);
    FileOutputStream fos = new FileOutputStream("./out/test/myfile");
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("./out/server.exe " + fileinputstring);
    StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERR", null);
    StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUT", fos);
    errorGobbler.start();
    outputGobbler.start();
    int exitVal = proc.waitFor();
    System.out.println("Exit Value: " + exitVal);
    fis.close();
    fos.flush();
    fos.close();
    catch(Throwable t)
         t.printStackTrace();
    }basically if my c program is to be run from the command prompt it would be:
    server outputfile/input.dat out/test/myfile
    my problem is that the file in out/test/myfile should contained the output that is generated from server...
    my code actually correctly print out the output i wan to see on screen but doesn't write the c output onto "myfile"...so i wonder whether i executed my program correctly this way..
    please help...thanks

  • Calling Same C program from Java Classes

    Hi!
    Can anyone let me know how to call the same C program using JNI from multiple Java Classes/programs?.
    Cheers
    Sai

    JNI creates a shared library.
    Any application that needs to can use the shared library at the same time.
    Ideally you use the same interface that you created for one application via JNI in the other applications.

  • How can i call a CGI script from java?

    The subject pretty much says it all. I want to call a perl cgi script so i can read from/write to files on a server. I don't know how to sign applets and this would be the easiest way for me, if someone could please tell me.

    Let me get this clear. Basically what u want to do is to just call a URL, right?
    U can do it by using the following code:
    import java.applet.*;
    import java.net.*;
    import java.io.*;
    public class testhttp
    public static void main(String[] args)
    try
    URL url = new URL ("http://../testcgi.cfm");
    HttpURLConnection cxn =
    (HttpURLConnection)url.openConnection();
    cxn.setRequestMethod("POST");
    cxn.setUseCaches(false);
    cxn.setDoOutput(true);
    cxn.setDoInput(true);
    ByteArrayOutputStream bytes = new
    ByteArrayOutputStream(400);
    PrintWriter writer = new PrintWriter (bytes,true);
    writer.print("application=map&release=1&items=prog1");
    writer.flush();
    cxn.setRequestProperty("Content-
    Length",String.valueOf(bytes.size()));
    cxn.setRequestProperty("Content-
    Type","application/x-www-form-urlencoded");
    bytes.writeTo(cxn.getOutputStream());
    System.out.println(bytes);
    String currentLine;
    BufferedReader in = new BufferedReader (new
    InputStreamReader(cxn.getInputStream(),"8859_1"));
    while((currentLine = in.readLine()) != null) {
    System.out.println(currentLine); }
    catch(Exception e) { e.printStackTrace(); }
    There is also a library called HTTP client which can be found at:
    http://www.innovation.ch/java/HTTPClient/index.html
    It's very simple to use and the documentation is all there, but their web server seems to be down right now.
    Anyway, hope my post helps.

  • How to call a BPEL process from Java ?

    How can I call a BPEL process from Java?
    The Java client should be outside of the PEL engine.
    Does someone have a piece of sample code for
    a "Hello world" java-to-bpel call (+ java client src)?

    http://www.oracle.com/technology/products/ias/bpel/pdf/orabpel-Tutorial7-InvokingBPELProcesses.pdf

  • Error in calling 'C'  Program from Java

    Hi,
    We developed a 'C' Program and during compilation, we got a couple of Incompatible Prototype warnings. Then we made a Jni call to 'C' program from Java Program. The program returned a "Unsatisfied Link Error - unreference Symbol not found" error.
    Does Jni call fails owing to warnings by compiler?
    We are using Sun Solaris 2.8.
    Request your assistance as this a urgent issue.
    Thanks
    Srini

    Did you try running your C program through g++? It sounds like something is broken, but GCC often will allow you to compile anyways.
    -Jason Thomas.

  • Problem while Calling a CGI pgm From Java with code sample

    Hey guys,
    I am calling a CGI program from java servlet, while calling cgi program I am passing encoded(Base64) content via post process,
    My problem is the encoded data is not posted as expected, the encoded data is corrupting. But when I send encoded data in a text file, cgi program is perfectly decoding and working fine.
    Here I am doing Base64 encoding as per requirement, I cannot avoid this encoding.
    My doubt is about OutputStreamWriter constructor argument , In OutputStream Constructor I am passing one argument is OutputStream object and another argument is encoding type. I tried with ASCII, US-ASCII & UTF-8 .
    My code is as follows, please help me to resolve this issue.
    URL url = new URL("CGI server path");
    URLConnection urlConnection = url.openConnection();
    urlConnection.setDoOutput(true);
    OutputStream os = urlConnection.getOutputStream();
    BufferedOutputStream buffer = new BufferedOutputStream(os);
    OutputStreamWriter  writer = new
                                                   OutputStreamWriter(buffer, "US-ASCII");
    writer.write(encodedPDF-Content);
    writer.write("\r\n");
    writer.flush();
    writer.close();
    here encodedPDF-Content is String and it's size is 9565 bytes

    Whenever you read something in java into string (with Reader implementation) it expects source to contain text in encoding you specified. It then decodes it and makes 16 bit unicode string from it. Whenever you store string using Writers it does reverse operation with specified encoding (may be different than this which you used to read source) and stores text as a sequence of bytes made of 16 bit unicode string. So, passing text back and forth between programs with the help of files or I/O you can make mistake at both reading and writing encoding. Check for it.
    Now, when C programm or other application reads file it may take another assumptions about encoding or may even completly ignore it and read source as a binary file. Then, if you have a source text as a file and have to pass it to other application never do it using Reader/Writer. User raw InputStream/OutputStream instead what will preserve all information unchanged.
    here encodedPDF-Content is String and it's size is 9565 byteHow id you get this info? String.length() gets you how many chars is in it, it will be half the number of bytes. If you see your input file beeing 9565 bytes long, see my above statements.

  • Calling a Web Service from Java

    Our java guru (who is out sick....AHHHH) created all the calls that are needed to access the web service that he has running. For example the call getLongList(String user, String password) will return a list of all outstanding transactions. He made a jar file that has service has class files for PortType, Service, Service Locator and Soap Binding stub.
    How do I call this web service from java? Do I have to import it into my classpath? or just call these parameters from within my java code?

    never mind...i got it

  • To call a VB dll from java

    Hi,
    I want to know how one can call a VB dll from Java.I know it is something like calling a C dll which in turn calls the VB dll.I also went through the tutorial provided on the sun site and was able to call a C dll through java but I still do not know how to call a VB dll from java.
    regards,
    Anshuman

    Have you checked google?
    First hit. Reply 17.

  • Calling a CGI pgm From Java

    I am calling a CGI program From Java using URL class and I am passing a pdf file under post process. The Content I am appending by Base64 encoding, the CGI program will decode it and print the content
    When I send this Content the content is correpting. When CGI program is decoding it is not getting expected content. But the CGI program is working fine If I send that encoded content in a text file.
    When I send the encoded content in a text file as attachment OR put in a common drive, the CGI program is working fine. Only I am facing problems when I send this content via post process using URL class.
    Why it is happening like this? Is anybody can help me to Resolve this problem?

    Just a guess: are you sure the content-type header is correct?

  • How to call a Dialog Program from another Dialog Program

    Dear All,
    How can I call a dialog program with return value from another dialog program?
    Regards,
    Alok.

    Hi Alok,
    1. Insted of creating 2 different Dialog program. It's good to create as many screens as you want in same module pool program. Any way you can use the different TCODE for each screen.
    2. Another and The best way is to create a function group and then inside function group use the function 2 module... In the function group define a global variable which will be present for both the function group if they are getting executed in sequence. and inside the Function Module call the screens using command " call screen <screenno>".
    3. You can use set / get parameter to pass values of a field between two dynpro program.

Maybe you are looking for