Executing JRE from within C in Linux

Hello,
I tried to execute the JRE and give it some arguments (In fact my Java application) from within C. I used the library function
execl(...) to make this.
Unfortunately I got error "Could not load JRE" and some
shared object error.
Anyone any ideas how I can execute my Java Application from within C in Linux?
thx Fatih

Look up Janava Native Interface (JNI), and specifically the invocation interface.

Similar Messages

  • Finding hard and soft open file limits from within jvm in linux

    Hi All,
    I have a problem where I need to find out the hard and soft open file limits for the process in linux from within a java program. When I execute ulimit from the terminal it gives separate values for hard and soft open file limits.
    From shell if I run the command then the output is given below:
    $ ulimit -n
    1024
    $ ulimit -Hn
    4096
    The java program is given below:
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.Reader;
    import java.io.StringWriter;
    import java.io.Writer;
    public class LinuxInteractor {
    public static int executeCommand(String command, boolean waitForResponse, OutputHandler handler) {
    int shellExitStatus = -1;
    ProcessBuilder pb = new ProcessBuilder("bash", "-c", command);
    pb.redirectErrorStream(true);
    try {
    Process shell = pb.start();
    if (waitForResponse) {
    // To capture output from the shell
    InputStream shellIn = shell.getInputStream();
    // Wait for the shell to finish and get the return code
    shellExitStatus = shell.waitFor();
    convertStreamToStr(shellIn, handler);
    shellIn.close();
    catch (IOException e) {
    System.out
    .println("Error occured while executing Linux command. Error Description: "
    + e.getMessage());
    catch (InterruptedException e) {
    System.out
    .println("Error occured while executing Linux command. Error Description: "
    + e.getMessage());
    return shellExitStatus;
    public static String convertStreamToStr(InputStream is, OutputHandler handler) throws IOException {
    if (is != null) {
    Writer writer = new StringWriter();
    char[] buffer = new char[1024];
    try {
    Reader reader = new BufferedReader(new InputStreamReader(is,
    "UTF-8"));
    int n;
    while ((n = reader.read(buffer)) != -1) {
    String output = new String(buffer, 0, n);
    writer.write(buffer, 0, n);
    if(handler != null)
    handler.execute(output);
    } finally {
    is.close();
    return writer.toString();
    } else {
    return "";
    public abstract static class OutputHandler {
    public abstract void execute(String str);
    public static void main(String[] args) {
    OutputHandler handler = new OutputHandler() {
    @Override
    public void execute(String str) {
    System.out.println(str);
    System.out.print("ulimit -n : ");
    LinuxInteractor.executeCommand("ulimit -n", true, handler);
    System.out.print("ulimit -Hn : ");
    LinuxInteractor.executeCommand("ulimit -Hn", true, handler);
    If I run this program the output is given below:
    $ java LinuxInteractor
    ulimit -n : 4096
    ulimit -Hn : 4096
    I have used ubuntu 12.04, Groovy Version: 1.8.4 JVM: 1.6.0_29 for this execution.
    Please help me in understanding this behavior and how do I get a correct result from withing the java program.

    Moderator Action:
    As mentioned in one of the earlier responses:
    @OP this is not a Java question. I suggest you take it elsewhere, i.e. to a Unix or Linux forum.You posted this to a Java programming forum.
    It is not a Java programming inquiry.
    This off-topic thread is locked.
    Additionally, you have answered your own question.
    Don't bother posting it to one of the OS forums. It will get deleted as a duplicate cross-post.

  • Executing WINWORD from both Windows and linux using Java

    Dear All,
    I have a problem when trying to use Runtime class to execute a winword document. My code is as follows.
    Runtime r= Runtime.getRuntime();
    try{
    r.exec("rundll32"+" "+"url.dll,FileProtocolHandler"+" "+"WINWORD"+ " "+"file://C://welkom.doc");
    catch(Exception ex){
    System.out.println("Unable to open the doc file:"+ex);
    When I execute this swing application with the above, the program is unable to open the specific file. And it says "Problem with the short cut, unable to open the file". When I run the program without the file name, it opens a new doc file.
    Attn: what I want to do here is I need to open the winword file from both windows and linux. So I cannot use the relative path of the WINWORD.exe file.
    Can anyone help me?
    Thanks in advance.
    Regards,
    Bala

    If you take a look at the api, there's an exec(String[]) method. This is the one you should use when calling a command with multiple parameters.
    so something like...
    String[] cmd = new String[] {"rundll32", "url.dll,FileProtocolHandler", "WINWORD", "file://C://welkom.doc"}
    r.exec(cmd);

  • Executing vbscript from within java

    Hi,
    Does anyone knows a way to execute a vbscript from within java and capture its output.
    thanks

    Do you mean emulate an interpreter?

  • Launching/executing files from within AIR

    Hi.
    Just wanted to know if I can launch files from within my AIR
    app...for instance I would like the user to click a button which
    then opens a Microsoft Word doc...the Word doc doesn't have to open
    in the AIR app, it can open on the desktop (Windows XP).
    Thanks for the help.

    Mike provided a good proof here:
    http://www.mikechambers.com/blog/2008/01/17/commandproxy-net-air-integration-proof-of-conc ept/
    HTH

  • Running executable jar from within a java program

    Is there a way to launch an executable jar in a java program? I tried wrapping the jar in an exe and calling it using Runtime exec() and though this approach works it does only for windows. I want it to work for unix/linux too.

    jaki wrote:
    Yes, but it's a sub process.Nope.
    Hence the calling process doesn't quit unless the called one returns.Wrong.
    My calling program is actually a jar and what Im trying to do is delete the jar after it's done running. But the above method (of launching a separate jar doing the deletion) doesn't seem to work for the above mentioned reason.Wrong.
    If you could tell me any other way it would really be a big help.You don't need any other way. Maybe you need to allow some time for the calling program to wind up. 20 seconds may be overkill, but I'm not in the mood to find how short it can be and still succeed.
    The two classes are packaged in separate jars.import java.io.IOException;
    public class Deletee {
        public static void main(String[] args) {
          try {
             String[] cmds = {"java", "-jar", "E:/temp/Deleter.jar"};
             Runtime.getRuntime().exec(cmds);
             System.exit(0);
          } catch (IOException ex) {
             ex.printStackTrace();
    import java.io.File;
    import javax.swing.JOptionPane;
    public class Deleter {
       public static void main(String[] args) {
          File file = new File("E:/temp/Deletee.jar");
          try {
             Thread.sleep(20000);
          } catch (InterruptedException ex) {
             ex.printStackTrace();
          if (file.delete()) {
             JOptionPane.showMessageDialog(null, "Deleted");
          } else {
             JOptionPane.showMessageDialog(null, "Oops");
    }Try it and see for yourself.
    db

  • How to open an executable file from within Captivate

    Hi guys,
    I wondered if any of you guys could help me...
    I am using Captivate 3 and I have created a project in this and exported it as a standalone executable file.
    Ideally I would like to link this to another standalone executable file exported from Captivate, so is it possible
    to create a button in the first file so when it has been exported, if I click on this it opens up the second standalone file?
    Thanks for your help in advance.
    br

    I'm pretty sure that, for security reasons, the projector app that Captivate uses for stand-alone EXEs is sandboxed: you won't be able to access the API of the host operating system, so you won't be able to launch any apps.

  • Execute exe From Within Prject Folder

    Hey Everyone,
    I have an executable file which carry's out some calculations that I have placed in my project folder. The file resides in /utilities/ImageExtracter.exe that is a folder called utilities under the root folder. I am currently executing the exe using the following code:
                   Process process = new ProcessBuilder(NEED RELATIVE ADDRESS HERE , documentPath,outputPath).start();
    Please let me know how I can get the address of the file as a string to use in the above code segment.
    Thanks,
    Nath5

    896350 wrote:
                   Process process = new ProcessBuilder(NEED RELATIVE ADDRESS HERE , documentPath,outputPath).start();Relative to what? Your "project"? There's no such thing as a "project" in Java. That's purely a construct of your IDE. Java code isn't usually run in an IDE except during development time for testing. My suggestion is to abandon the IDE, and write your code with a text editor or programmer's editor, and compile and run on the command line. That way there will be less chance of conflating the tools with the Java language and API.
    If you're going to insist on continuing with the IDE, then your question of how to find the "project" folder is best addressed to that IDE's support forum or whatever they offer.

  • PL/SQL: Executing a procedure from within another procedure

    Hello, I'm a newbie and I need help on how to execute procedures from within another procedure. The procedure that I call from within the procedure have return values that I want to check.
    I tried: EXECUTE(user_get_forum_info(p_forumid, var_forum_exists, var_forum_access, var_forumname));
    but I get the error message:
    PLS-00103: Encountered the symbol "USER_GET_FORUM_INFO" when expecting one of the following::= . ( @ % ; immediate
    The symbol ":=" was substituted for "USER_GET_FORUM_INFO" to continue.
    And when I tried: EXECUTE(user_get_forum_info(p_forumid, var_forum_exists, var_forum_access, var_forumname));
    I get the error message:
    PLS-00222: no function with name 'USER_GET_FORUM_INFO' exists in this scope
    PL/SQL: Statement ignored
    The procedure USER_GET_FORUM_INFO exists. (don't understand why it says "no FUNCTION with name", it's a procedure I'm executing)
    I'm stuck so thanks for any help...
    Below is all the code. I'm using Oracle 9i on RedHat Linux 7.3.
    ================================================================================
    CREATE OR REPLACE PROCEDURE user_forum_requestsaccess (
    p_forumid IN NUMBER,
    p_requestmessage IN VARCHAR2
    AS
    var_forumid NUMBER;
    var_forum_exists NUMBER;
    var_forum_access NUMBER;
    request_exists NUMBER;
    var_forumname VARCHAR2(30);
    FORUM_DOESNT_EXIST EXCEPTION;
    FORUM_USER_HAS_ACCESS EXCEPTION;
    FORUM_REQUEST_EXIST EXCEPTION;
    BEGIN
    SELECT SIGN(NVL((SELECT request_id FROM forum.vw_all_forum_requests WHERE forum_id = p_forumid AND db_user = user),0)) INTO request_exists FROM DUAL;
    EXECUTE(user_get_forum_info(p_forumid, var_forum_exists, var_forum_access, var_forumname));
    IF var_forum_exists = 0 THEN
    RAISE FORUM_DOESNT_EXIST;
    ELSIF var_forum_access = 1 THEN
    RAISE FORUM_USER_HAS_ACCESS;
    ELSIF request_exists = 1 THEN
    RAISE FORUM_REQUEST_EXIST;
    ELSE
    INSERT INTO tbl_forum_requests VALUES (SEQ_TBL_FORUM_REQ_REQ_ID.NEXTVAL, SYSDATE, p_requestmessage, p_forumid, user);
    INSERT INTO tbl_forum_eventlog VALUES (SEQ_TBL_FORUM_EVNTLOG_EVNT_ID.NEXTVAL,SYSDATE,1,'User ' || user || ' requested access to forum ' || var_forumname || '.', p_forumid,user);
    COMMIT;
    END IF;
    EXCEPTION
    WHEN
    FORUM_DOESNT_EXIST
    THEN RAISE_APPLICATION_ERROR(-20003,'Forum doesnt exist.');
    WHEN
    FORUM_USER_HAS_ACCESS
    THEN RAISE_APPLICATION_ERROR(-20004,'User already have access to this forum.');
    WHEN
    FORUM_REQUEST_EXIST
    THEN RAISE_APPLICATION_ERROR(-20005,'A request to this forum already exist.');
    END;
    GRANT EXECUTE ON user_forum_requestsaccess TO forum_user;
    ================================================================================
    Regards Goran

    you don't have to use execute when you want to execute a procedure (only on sql*plus, you would use it)
    just give the name of the funtion
    create or replace procedure test
    as
    begin
        dbms_output.put_line('this is the procedure test');
    end test;
    create or replace procedure call_test
    as
    begin
        dbms_output.put_line('this is the procedure call_test going to execute the procedure test');
        test;
    end call_test;
    begin
        dbms_output.put_line('this is an anonymous block calling the procedure call_test');
        call_test;
    end;
    /

  • How to execute a Perl program from within a Java prog

    How do I execute a Perl program from within a Java program.
    Lets say the Perl program that I want to execute is 'abc'. Now, 'abc' requires some input that I want to give it from within the Java program. How do I do it?
    And finally, how do I execute that Perl program from within the Java program.
    If I execute the Perl program alone then I do it in the following way -
    perl abc inp1 inp2 inp3
    where inp1, inp2, inp3 are inputs to the Perl program. I will not be able to change or modify the coding of the Perl program - 'abc' as I do not have access to its code. Its a kind of an application whose usual method of execution is in the above shown way. So, how do I execute 'abc' from within a Java program.

    what part of don't crosspost, don't you understand?
    http://forum.java.sun.com/thread.jsp?forum=4&thread=427193

  • Trying to run an .exe from within pdf

    I am trying to run an executable file from within a pdf.  I get the error "This file is set to be launched by this pdf file.  This is currently disallowed by your administrator."  Error box is labeled "acrobat.exe"
    Using:  Adobe Acrobat 9 pro
    Windows 7
    This has worked with previous versions of Acrobat, is it still possible to do?

    This is disallowed for security reasons.
    See the "attachment configuration" section at : http://learn.adobe.com/wiki/display/security/Application+Security+Library to change this behavior.

  • Executing Stored Procedure within Excel

    I am in the middle of setting up an Excel spreadsheet that will execute a stored procedure I have created and return the results to Excel. Pretty much following the example set here: 
    http://datapigtechnologies.com/blog/index.php/running-a-sql-stored-procedure-from-excel-with-dynamic-parameters/
    But, the problem I am stuck on and unable to yet find an answer to, is can I execute the procedure from within Excel and instead of specifying a parameter enter a WHERE clause. At the moment the last step of my stored procedure is:
    SELECT * FROM MY_TABLE
    WHERE ([PRODUCT] LIKE 'DESK-%') AND (NOT([DISCOUNT VALUE] IS NULL))
    But, I cannot find if it is possible to execute this from within Excel. I am not sure if it I am able to set the WHERE as a parameter which may be the way I should be going about this. 
    Thanks.

    Are you invoking a stored procedure, or are you sending a SELECT statement (ad-hoc query) to the SQL Server?  It seems like you are sending an ad-hoc query.
    If that is the case, I would not put the entire WHERE clause as a parameter. I would do it something like this:
    "SELECT * FROM MY_TABLE WHERE ([PRODUCT] LIKE '" & Range("B2").Value & "%') AND (NOT([DISCOUNT VALUE] IS NULL))"
    That assumes that the parameter that you want to use is in cell B2.
    Ideally, I would prefer not to use ad-hoc queries. Instead, create a stored procedure which takes the Product type as a parameter.  There are lots of examples on the net on how to query SQL Server from Excel via a stored procedure with parameters.

  • How to run mxmlc from within an Adobe AIR application

    Hi. I'm at the planning stages of writing an Adobe AIR application that needs to be able to run the mxmlc Flex compiler from within. I don't know if this is possible, but if it is, then there are 2 things I don't know how to do:
    1) I don't know what classes to use to execute mxmlc from within my AIR application;
    2) I don't know how to register a listener to such so that the application will know when mxmlc has finished its execution.
    Any help on this would be immensely appreciated. Thanks in advance.

    There is a detailed article on Runtime
    [url http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps_p.html]here

  • How do I access BSD file tree from within Linux?

    I just installed PC-BSD 8.0 RC on an external USB HDD.  I went with the PC-BSD default partition layout, i.e. one primary partition for the entire PC-BSD slice, and 4 "partitions" within that slice, for /, swap, /usr and /var.
    In order to access the PC-BSD file tree from within Linux, I mount it as follows:
    mount -t ufs -o ufstype=ufs2,ro /dev/sdb1 /mnt/bsd
    But after executing this command I can only access the PC-BSD / , not /usr and /var , presumably because they reside on two BSD "partitions" (subslices) different from / .  Is there any way I can mount these (read-only) in Linux, too, or would I have to reinstall PC-BSD and opt for laying out the slice differently, i.e. specifying only / and swap in sdb1?
    Last edited by RobF (2010-02-13 11:55:39)

    Look at  /dev/sdb*  there should be more than just sdb1.  You would need to mount those to see which is which.  For ufs write support the default kernel needs to be recompiled with experimental enabled.

  • How can I execute an external program from within a button's event handler?

    I am using Tomcat ApacheTomcat 6.0.16 with Netbeans 6.1 (with the latest JDK/J2EE)
    I need to execute external programs from an event handler for a button on a JSF page (the program is compiled, and extremely fast compared both to plain java and especially stored procedures written in SQL).
    I tried what I'd do in a standalone program (as shown in the appended code), but it didn't work. Instead I received text saying the program couldn't be found. This error message comes even if I try the Windows command "dir". I thought with 'dir' I'd at least get the contents of the current working directory. :-(
    I can probably get by with cgi on Apache's httpd server (or, I understand tomcat supports cgi, but I have yet to get that to work either), but whatever I do I need to be able to do it from within the button's event handler. And if I resort to cgi, I must be able to maintain session jumping from one server to the other and back.
    So, then, how can I do this?
    Thanks
    Ted
    NB: The programs that I need to run do NOT take input from the user. Rather, my code in the web application processes user selections from selection controls, and a couple field controls, sanitizes the inoputs and places clean, safe data in a MySQL database, and then the external program I need to run gets safe data from the database, does some heavy duty number crunching, and puts the output data into the database. They are well insulated from mischeif.
    NB: In the following array_function_test.pl was placed in the same folder as the web application's jsp pages, (and I'd tried WEB-INF - with the same result), and I DID see the file in the application's war file.
            try {
                java.lang.ProcessBuilder pn = new java.lang.ProcessBuilder("array_function_test.pl");
                //pn.directory(new java.io.File("K:\\work"));
                java.lang.Process pr = pn.start();
                java.io.BufferedInputStream bis = (java.io.BufferedInputStream)pr.getInputStream();
                String tmp = new String("");
                byte b[] = new byte[1000];
                int i = 0;
                while (i != -1) {
                    bis.read(b);
                    tmp += new String(b);
                getSelectionsDisplayTextArea().setText(getSelectionsDisplayTextArea().getText() + "\n\n" + tmp);
            } catch (java.io.IOException ex) {
                getSelectionsDisplayTextArea().setText(getSelectionsDisplayTextArea().getText() + "\n\n" + ex.getMessage());
            }

    Hi Fonsi!
    One way to execute an external program is to use the System Exec.vi. You find it in the functions pallet under Communication.
    /Thomas

Maybe you are looking for

  • How do I get my plugins to work?

    I have just upgraded (?)  to Elements 13 but I cannot get my plugins to work...... If I use the "Additional Plugins"  option you can only have 1 plugin at a time working.   I use the Nik collection and also DXO Viewpoint 2 if they are not going to wo

  • Can I use iCloud to store my music to free up space on my computer?

    The idea is to upload/match all of my songs so I can take them off my hard drive. Music is taking up way too much space. Is it possible to do that?

  • N900 key input issue

    is there any way to reinstall english-netherlands key input? one stupid app permanently remapped the keys making 3 keys unusable, other ones work, but dont fit my physical keyboard

  • ABAP for dummies???

    Hello there, I am new in ABAP. Does somebody have a document or documents with some exercises that i can do with getting started with ABAP?I would like do to some exercises.

  • Upgraged to ios 6 and lost all pictures, any way to recover them?

    upgraded to ios 6. and lost all my pictures. Don't have a backup. Is there anythig I can do to recover them?