Results 1 to 7 of 7
  1. #1
    rach is offline Member
    Join Date
    Jul 2007
    Posts
    6
    Rep Power
    0

    Unhappy urgent:calling c program from java

    hii
    i have a c program (unix)...which is to find process info..
    now i want to call that from java ...
    wat do i do?:confused: :eek: :(


    please help

  2. #2
    henry_78 is offline Member
    Join Date
    Aug 2007
    Posts
    47
    Rep Power
    0

    Default

    Hi,
    what do u mean by colling it..?
    U want only to run the C application or u want it to be interactve with your java program?

  3. #3
    rach is offline Member
    Join Date
    Jul 2007
    Posts
    6
    Rep Power
    0

    Default

    i want to run the c program form the java program

  4. #4
    henry_78 is offline Member
    Join Date
    Aug 2007
    Posts
    47
    Rep Power
    0

    Default

    There are many ways,
    U can open a console from java and execute a comand tha runs the c program...is that what u want?

  5. #5
    rach is offline Member
    Join Date
    Jul 2007
    Posts
    6
    Rep Power
    0

    Default

    umm..yeah...
    can yu gimme a sample code?

  6. #6
    henry_78 is offline Member
    Join Date
    Aug 2007
    Posts
    47
    Rep Power
    0

    Default

    Yes..try this:
    Runtime rt = Runtime.getRuntime();
    String command = "cmd /c 'command_to launch_ c_program' ";
    Process p = null;
    try {
    p = rt.exec(command);
    }
    catch(IOException e) {
    }

    This is ok if your platform is windows.
    U have to substitute the 'command_to launch_ c_program' with the command that u use normaly to lanuch your c program from console..
    Have fun..Bye.

  7. #7
    Varun12345 is offline Member
    Join Date
    Jan 2010
    Posts
    4
    Rep Power
    0

    Default

    helloworld.java

    class HelloWorld {
    public native void displayHelloWorld();

    static {

    System.loadLibrary("hello");
    }

    public static void main(String[] args) {
    System.out.println("\n Hey now calling display method\n");
    new HelloWorld().displayHelloWorld();
    }
    }


    also a c program

    helloworldImp.c

    #include<jni.h>
    #include"HelloWorld.h"
    #include<stdlib.h>
    #include<iostream.h>
    #include<conio.h>

    JNIEXPORT void JNICALL
    Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
    {
    printf("\n Hello compiling C file !!!! \n " );
    return;
    }


    using as

    java helloworld.java

    javah -jni helloworld

    gcc -I c:\jdk\include -g -c helloworldImp.c -o libhello.so

    java helloworld

    may it work

Similar Threads

  1. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  2. Urgent Opening in C++/Java with SIP/VoIP
    By Satish.kumar in forum Jobs Offered
    Replies: 3
    Last Post: 03-30-2008, 10:24 AM
  3. Calling mainframe IMS program from Java
    By babu95 in forum New To Java
    Replies: 2
    Last Post: 12-21-2007, 02:08 PM
  4. Urgent Requirement for Java/J2ee
    By anushareddy7480 in forum Java Software
    Replies: 1
    Last Post: 07-23-2007, 02:35 PM
  5. Urgent Requirement for Java/J2ee
    By anushareddy7480 in forum New To Java
    Replies: 0
    Last Post: 07-23-2007, 12:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •