Calling a function in an EXE file from Java Program

Hi Im having a function which is written in c program.i need to call that function from my java program, if i create a shared library (DLL) for my C code then it works but my requirement is i dont want to create that DLL , like in it would be an executable and my java code should access that function in that C program

I understand the usage od a DLL but the thing is if i convert the exe to a DLL
the server doesnt start at all so what i need is that i dont want to change
that .EXE into a .DLL,let it be an executable. that executable is in running mode
and through my java program i need to call a function in that EXE file.
Is ther any way to do it?Nope, but you have another problem: why can't you separate your server program
into a .dll part and a startup part? Both, when properly linked against each other
should give you an executable file.
kind regards,
Jos

Similar Messages

  • Need urgent help. Calling of exe files from java program

    This program can execute small .exe files that donot take inputs but doesn't work for exe files that takes input. what could be the problem.
    Server code :-
    import java.io.*;
    import java.net.*;
    public class Server1 {
         private Player[] players;
         private ServerSocket server;
         private ExecHelper exh;
         String command = null;
         String message = null;
         public Server1() {
              players = new Player[5];
              try {
                   server = new ServerSocket( 12345, 5 );
                   System.out.println("Server started...");
                   System.out.println("Waiting for request...");
              catch( IOException ioe ) {
                   ioe.printStackTrace();
                   System.exit( 1 );
         } //end Server constructor
         public void execute() {
              for( int i = 0; i < players.length; i++ )
              try {
                   players[i] = new Player( server.accept() );
                   players.start();
              catch( IOException ioe ) {
                   ioe.printStackTrace();
                   System.exit( 1 );
         public static void main( String args[] ) {
              Server1 ser = new Server1();
              ser.execute();
              System.exit( 1 );
         private class Player extends Thread {
              private Socket connection;
              private ObjectOutputStream output;
              private ObjectInputStream input;
              public Player( Socket socket ) {
                   connection = socket;
                   try {
                        input = new ObjectInputStream( connection.getInputStream());
                        output = new ObjectOutputStream( connection.getOutputStream());
                        output.flush();
                   catch( IOException ioe ) {
                        ioe.printStackTrace();
                        System.exit( 1 );
              public void run() {
                   try {
                        message = "Enter a command:";
                        output.writeObject( message );
                        output.flush();
                        do {
                             command = ( String ) input.readObject();
                             String osName = System.getProperty( "os.name" );
                             String[] cmd = new String[3];
                             if( osName.equals( "Windows 2000" )) {
                                  cmd[0] = "cmd.exe";
                                  cmd[1] = "/c";
                                  cmd[2] = command;
                             else if( osName.equals( "Windows NT" ) ) {
                             cmd[0] = "cmd.exe" ;
                             cmd[1] = "/C" ;
                             cmd[2] = command ;
                             Runtime rt = Runtime.getRuntime();
                             Process proc = rt.exec( cmd );
                             exh = new ExecHelper( proc, output, input);
                        } while( !command.equals( "TERMINATE" ) );
                   catch( Throwable t ) {
                        t.printStackTrace();
         } //end class Player
         public class ExecHelper implements Runnable {
         private Process process;
         private InputStream pErrorStream;
         private InputStream pInputStream;
         private OutputStream pOutputStream;
         private InputStreamReader isr;
         private InputStreamReader esr;
         private PrintWriter outputWriter;
         private ObjectOutputStream out;
         private ObjectInputStream in;
         private BufferedReader inBuffer;
         private BufferedReader errBuffer;
         private Thread processThread;
         private Thread inReadThread;
         private Thread errReadThread;
         private Thread outWriteThread;
         public ExecHelper( Process p, ObjectOutputStream output, ObjectInputStream input ) {
              process = p;
              pErrorStream = process.getErrorStream();
              pInputStream = process.getInputStream();
              pOutputStream = process.getOutputStream();
              outputWriter = new PrintWriter( pOutputStream, true );
              in = input;
              out = output;
              processThread = new Thread( this );
              inReadThread = new Thread( this );
              errReadThread = new Thread( this );
              outWriteThread = new Thread( this );
              processThread.start();
              inReadThread.start();
              errReadThread.start();
              outWriteThread.start();
         public void processEnded( int exitValue ) {
              try {
                   Thread.sleep( 1000 );
              catch( InterruptedException ie ) {
                   ie.printStackTrace();
         public void processNewInput( String input ) {
              try {
                   out.writeObject( "\n" + input );
                   out.flush();
                   catch( IOException ioe ) {
                   ioe.printStackTrace();
         public void processNewError( String error ) {
              try {
                   out.writeObject( "\n" + error );
                   out.flush();
         catch( IOException ioe ) {
                   ioe.printStackTrace();
         public void println( String output ) {
              outputWriter.println( output + "\n" );
         public void run() {
              if( processThread == Thread.currentThread()) {
                   try {
                        processEnded( process.waitFor());
                   catch( InterruptedException ie ) {
                        ie.printStackTrace();
              else if( inReadThread == Thread.currentThread() ) {
                   try {
                        isr = new InputStreamReader( pInputStream );
                        inBuffer = new BufferedReader( isr );
                        String line = null;
                        while(( line = inBuffer.readLine()) != null ) {
                                  processNewInput( line );
                   catch( IOException ioe ) {
                        ioe.printStackTrace();
              else if( outWriteThread == Thread.currentThread() ) {
                   try {
                        String nline = null;
                        nline = ( String ) in.readObject();
                        println( nline );
                   catch( ClassNotFoundException cnfe ) {
                   //     cnfe.printStackTrace();
                   catch( IOException ioe ) {
                        ioe.printStackTrace();
              else if( errReadThread == Thread.currentThread() ) {
                   try {
                        esr = new InputStreamReader( pErrorStream );
                        errBuffer = new BufferedReader( esr );
                        String nline = null;
                        while(( nline = errBuffer.readLine()) != null ) {
                             processNewError( nline );
                   catch( IOException ioe ) {
                        ioe.printStackTrace();
    Client code :-
    // client.java
    import java.io.*;
    import java.net.*;
    public class Client {
         private ObjectOutputStream output;
         private ObjectInputStream input;
         private String chatServer;
         private String message = "";
         private Socket client;
         public Client( String host ) {
              chatServer = host;
         private void runClient() {
              try {
                   connectToServer();
                   getStreams();
                   processConnection();
              catch( EOFException eofe ) {
                   System.err.println( "Client terminated connection ");
              catch( IOException ioe ) {
                   ioe.printStackTrace();
              finally {
                   closeConnection();
         } //end method runClient
         private void connectToServer() throws IOException {                                                                 
              System.out.println( "Attempting connection...\n");
              client = new Socket( InetAddress.getByName( chatServer ), 12345);
              System.out.println( "Connected to : "+ client.getInetAddress().getHostName());
         private void getStreams() throws IOException {
              output = new ObjectOutputStream( client.getOutputStream());
              output.flush();
              input = new ObjectInputStream( client.getInputStream());
         private void processConnection() throws IOException {
         while( true ){
                   try {
                        message = ( String ) input.readObject();
                        System.out.print( message );
                        InputStreamReader isr = new InputStreamReader( System.in);
                        BufferedReader br = new BufferedReader( isr );
                        String line = null ;
                        line = br.readLine();
                             output.writeObject(line);
                             output.flush();
                   catch( ClassNotFoundException cnfe) {
                        System.out.println( "\nUnknown object type received");
         } //end processConnection
         private void closeConnection() {
              System.out.println( "\nClosing connection");
              try {
                   output.close();
                   input.close();
                   client.close();
              catch( IOException ioe ) {
                   ioe.printStackTrace();
         public static void main( String args[] ) {
              Client c;
              if( args.length == 0 )
                   c = new Client( "127.0.0.1" );
              else
                   c = new Client( args[0] );
              c.runClient();

    maybe you should
    1. Use code tags so the posted code is understandable
    2. Stop marking your post urgent, that just puts peoples backs up
    3. Stop posting the question every couple of hours on every imaginable forum.. Post it once and start a single dialog

  • How to call c functions that expects c structs from java program?

    i need to call from my java program to c functions that get
    c structs as a parameters in their prototype.
    as you probablly know java is not working with structs (classes only), so my question is how can i do it , i mean call the c functions that gets structs as parameters form java????

    i believe your c function can accept a jobject and then inside your c function you have to translate that jobject into a c struct by using the jni methods.
    the only reason your c function cant accept structs from java is because java does not have such structures. your c function can accept any data type that has been defined and a jobject has been defined.
    if you have no control over the c functions that are being called, you need to write a wrapper function for those c function. the wrapper functions do the translation from jobject to a struct...then call the c other c functions.

  • Executing exe files from java program

    Hi,
    I need to execute exe files and pass arguments to them from my java code.
    Can you give me guidelines to do that as i haven't done that before.
    Thanks.

    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
    getRuntime() method.
    exec() method.

  • How to call a function in one .js file from another .js file

    Hello Techies,
    I am trying to call a function in two.js file from one.js file.
    Here is my code
    one.js
    <script>
    document.write("<script type='text/javascript' src='/htmls/js/two.js'> <\/script>");
         function one()
                        var a;
                       two(a);
              }two.js
                  function two(a)
                          alert("two");
                      }But the function two() is not working.
    How can I do this one??
    regards,
    Krish

    I think there is a syntax error in line
    document.write("<script type='text/javascript' src='/htmls/js/two.js'> <\/script>");
    end tag <\/script> is wrong.

  • I wants to call .Exe file from Java Programme

    I wants to call .Exe file from Java programme. Please give answer with example. This very urgent. Help me

    hi
    u can use Runtime.exec() method in java.lang package
    to execute exe files
    regards
    pnp

  • Calling C Functions in existing DLL's from Java

    Hi Guys ,
    The tutorial in this site talks about creating ur own DLL's and then calling them from Java . I need to call C functions in existing DLL's from Java . How do I go about doing this ? . Any help on this would be much appreciated.
    regards
    murali

    What you are interested in can be done with what's called "shared stubs", from the JNI book (http://java.sun.com/products/jdk/faq/jnifaq.html), although you don't need the book to do it (I didn't).
    The example code will call functions with any number and kind of parameters, but doing that requires some assembly language. They supply working examples for Win32 (Intel architecture) and Solaris (Sparc).
    If you can limit yourself to functions to a single function signature (number and types of parameters), or at least a small set that you know you'll call at compile time, you can modify the example so that the assembly language part isn't needed, just straight C code.
    Then you'll have one C library that you compile and a set of Java classes and you can load arbitrary functions out of arbitrary dynamic libraries. In my case you don't even have to know what the libraries and functions are ahead of time, the user can set that up in a config file.
    You mentioned doing this with Delphi. One thing to watch out for is C versus Pascal (Win32) function calling convention. A good rule of thumb; if it crashes hard, you probably picked the wrong one, try the other. :-)

  • .exe file from java

    Hi all !!!
    Is it possible to run a *.exe file from java.....
    if yes how??
    if no why not??
    regards
    ad

    Yes. It's possible. One of the Runtime.exec() methods are probably what you want:
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
    You can't instantiate a Runtime object, so you'll need to call it up by:
    Runtime.getRuntime()
    For example, if you want to run the Calculator in Windows, try:
    Runtime.getRuntime().exec("calc");

  • How to Call .XDO file From Java Program

    Hi,
    I have developed a report in using BI Publisher version 10.1.3.
    I created the report and it only created XDO files. If I want to call XDO file from Java program how I can do that.
    What are the APIs available to do that.
    Thanks
    -Ashutosh

    Hi,
    the JavaAPI didn't work with the xdo-Files. But you can create a proxy stub for the Web Service API of BI Publisher which uses the xdo's in the repository.
    regards
    Rainer

  • How to make Exe file of java program

    how we can make the exe file of java programs. that can run independently of particuler JVM. like in VB we can create exe files.
    - early thanks

    Check this out:
    http://search.java.sun.com/search/java/index.jsp?qp=%2B
    orum%3A31&nh=10&qt=create+exe+file+program&col=javaforu
    s

  • Calling exe files from java

    heyy
    can anybody please help me out in calling an exe file using java??
    also i would like to pass parameters tooo.
    i have been trying the following runtime code
    but found no success
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("make.exe 12");
    proc.waitFor();
    int exitVal = proc.exitValue();
    Does anybody havea better soultion???
    Thanks for your time
    Rachit

    Read this article, please http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Need to create a function to receive binary files from Java WebDynpro

    Hey,
    I need to recieve files from java Webdynpro and save them as a file on the backend
    system. After that, the file will be loaded to the documentum.
    In a function module, I only can get the files as a String. Therefore (I think), I need the
    binary file as base64 encoded. Otherwise I can´t get it as a string.
    Now I need to decode it in the backend, but how? I know, there are HTTP-classes
    in newer system, but not in the 4.6C System, I have here.
    Any idea, how I can recieve the files in the function module and transfer it as binary
    file to the backend system?
    If I load a file from the gui with gui_upload, I get the binary file as an internal table
    and can transfer it to the backend filesystem now. Maybe I can get the binary file
    in this way in the function?
    Thank You for Your help!
    Arne

    http://jakarta.apache.org/commons/net/

  • Running exe files from java applications

    Hello All,
    Is it possible to run executable files from java applications?
    I need to run an exe file on the client from the server machine, the exe could reside on either the server or any other machine on the LAN. Is it possible to specify the path of where the exe resides, and run it on a client machine?

    HI,
    I tried to launch a MS Word application using runtime.exec but it gives me some problem
    The foll. code to launch a txt file using notepad works.
    Runtime rt = Runtime.getRuntime();
    String[] callAndArgs = {"notepad.exe","C:\\coo7\\wizard.txt"};
    Process child = rt.exec(callAndArgs);
    However, oif I try to launch a MS Word application, it asks for the entire path of WINWORD.exe, (unlike just specifying notepad.exe as the first argument in String[] callAndArgs) and this can vary from one machine to another.. how do I get around this?
    The foll. code snippet works but the complete path of where WINWORD.exe might be installed on any machine, is not fixed:-(
    Runtime rt = Runtime.getRuntime();
    String[] callAndArgs = {"C:\\Program Files\\Office\\Office10\\WINWORD.exe","C:\\coo7\\wizard.doc"};
    Process child = rt.exec(callAndArgs);
    Any idea/suggestions pls..

  • Running an exe file from java

    Hi , can anyone tell me how to run an exe file from my java program. the exe is in the same directory as my java files . When i click on a button i want to put something in the actionPerformed() method which will launch the exe file - prog.exe
    Hope someone can help me.
    Thanks Jim

    Hi !
    Look at the RunTime class...

  • Invoking exe file through java program

    I have one exe file,which i want to invoke it from java program.I have used Runtime class to execute the exe, but it throws an exception
    java.io.IOException: CreateProcess: afp2web.exe -q -PDF -c -fm samples\medform.a
    fp error=2
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Unknown Source)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at Afp2PdfDemo.main(Afp2PdfDemo.java:7)
    However if i give the absolute path of exe file then it doesn't throw an exception but at the same time,it doesn't the do the expected job.
    Can somebody throw some light on this?
    Thanx in advance
    Regards,
    Pulak

    Have you tried also supplying the absolute paths of the file arguments like "samples\medform.a"?

Maybe you are looking for

  • IOS 6 Update ruined my 4s.

    I bought my iphone 4s on December 25th 2011. It worked perfectly, I absolutely love my phone. Although, ever since I downloaded the IOS6 Update, it has been glitching, crashing, and I've had to reboot it about 5X a day. It's not fair.. I payed 700$ f

  • Find files on Time Machine that weren't in the "Latest Backup"?

    I restored my new Mac with the "Latest Backup" of Time Machine. I now understand that I will have to erase the whole backup harddrive in order to continue using Time Machine (I cannot get it to do incremental backups with my new computer from where I

  • Missing Text when using CONVERT to PDF

    I am using Acrobat Pro 9 in Wnidows 7 and Microsoft Publisher 2003. When I use the CONVERT command to create a PDF - it is missing all of the text on the master page. If I create the PDF with the PRINT command - everything is OK. PS: The same Publish

  • Oc4j logging

    Hi! I'm new to OC4J and hope I can get help here. Using following (in an action class of a Struts based web app): private Log log = LogFactory.getLog("com.abc.xyz"); og.info("---->>>test of info log."); og.debug("---->>>test of debug log."); 1st line

  • Japanese character storing format.

    Hi all, I have stored japanese characters in varchar field in the format 'し' for 'し' i.e. 'shi' and so on. Does any one know what this format is called and are there any other formats for storing such different language characters and also how to use