calling "java from C dll" (system command??)

Discussion in 'Java' started by jobs239@hotmail.com, Jul 21, 2006.

  1. Guest

    Can I use this line inside C program "system(java -jar <jarfilename>)"
    to run a java program from C?

    Or do I have to use some JNI interface.?
    , Jul 21, 2006
    #1
    1. Advertising

  2. Flash Gordon Guest

    wrote:
    > Can I use this line inside C program "system(java -jar <jarfilename>)"
    > to run a java program from C?


    You can, but whether it works depends on things outside the C language.

    > Or do I have to use some JNI interface.?


    You may be able to do that as well.

    The best solution will depend on what you are trying to achieve, and you
    would be better off discussing it in a group dedicated to your
    implementation or, depending on what they consider topical, a Java group
    than on comp.lang.c (I've no idea about comp.lang.java.programmer).

    Follow-ups set, since solving the OPs problem will involve things beyond
    the scope of standard C and so is off topic for comp.lang.c
    --
    Flash Gordon, living in interesting times.
    Web site - http://home.flash-gordon.me.uk/
    comp.lang.c posting guidelines and intro:
    http://clc-wiki.net/wiki/Intro_to_clc
    Flash Gordon, Jul 21, 2006
    #2
    1. Advertising

  3. On 2006-07-21, <> wrote:
    > Can I use this line inside C program "system(java -jar <jarfilename>)"
    > to run a java program from C?
    >


    No. That's a either a string literal or a syntax error, depending on
    whether you preserve your quotes.

    > Or do I have to use some JNI interface.?
    >


    I don't know. Unfortunately, I can't think of who /would/ know, so I
    can't redirect you.
    Andrew Poelstra, Jul 21, 2006
    #3
  4. jacob navia Guest

    wrote:
    > Can I use this line inside C program "system(java -jar <jarfilename>)"
    > to run a java program from C?
    >
    > Or do I have to use some JNI interface.?
    >


    There is a very simple way to verify this:

    1) open a command shell
    2) type in that command shell
    java -jar filename

    If that works, then the C function call
    system("java -jar filename");

    will work too. Note the correct quotes, and not
    as you typed...

    jacob
    jacob navia, Jul 21, 2006
    #4
  5. Malcolm Guest

    <> wrote
    > Can I use this line inside C program "system(java -jar <jarfilename>)"
    > to run a java program from C?
    >
    > Or do I have to use some JNI interface.?
    >

    System is the portable, ANSI C way of doing it.
    Usually portable, ANSI methods are best, but "system" is often an exception.
    There might be a better way that doesn't rely on your user having all his
    paths set up correctly.
    --
    Buy my book 12 Common Atheist Arguments (refuted)
    $1.25 download or $7.20 paper, available www.lulu.com/bgy1mm
    Malcolm, Jul 22, 2006
    #5
  6. Richard Bos Guest

    jacob navia <> wrote:

    > wrote:
    > > Can I use this line inside C program "system(java -jar <jarfilename>)"
    > > to run a java program from C?

    >
    > There is a very simple way to verify this:
    >
    > 1) open a command shell
    > 2) type in that command shell
    > java -jar filename
    >
    > If that works, then the C function call
    > system("java -jar filename");
    >
    > will work too.


    This is far from guaranteed. It's a start; but it's not enough for
    certainty.

    > Note the correct quotes, and not as you typed...


    True.

    Richard
    Richard Bos, Jul 24, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Elhanan
    Replies:
    6
    Views:
    604
    Owen Jacobson
    Mar 5, 2006
  2. Irmen de Jong
    Replies:
    2
    Views:
    426
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=
    Aug 12, 2003
  3. Replies:
    11
    Views:
    581
    Mark McIntyre
    Jul 25, 2006
  4. boriq
    Replies:
    4
    Views:
    578
    Tim Golden
    Jun 12, 2008
  5. Gary Perkins

    calling system command as another user

    Gary Perkins, Jul 15, 2003, in forum: Perl Misc
    Replies:
    4
    Views:
    130
Loading...

Share This Page