🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #19240

Re: JNI example requested

#19240
From: James D. Frentress
Date: Thu, 26 Feb 1998 00:00
43 lines
1847 bytes
Bill Freiberg wrote:

> I am writing an app which will need to execute a non-java program on
> my
> WIN95 client. I looked thru several java books for examples on using
> JNI,
> and while some books did contain examples, they were not clear. I do
> not
> have a C background so I am sure that this is contributing to my
> confusion.
> Can anyone provide a simple example of execution  mynonjava.exe in a
> java
> app. Any and all help would be GREATLY appreciated.

A simple way to execute follows. This synchronizes the call, async is
even easier.


/************************************************************************

  Purpose:   Synchronously run arbitrary commands at the system level
  Accepts:   commandToRun
  Returns:   n/a
  Notes:     Runs synchronously - blocks calling thread until finished

*************************************************************************/

  public static void shellSync(String commandToRun) {
    try {
      Process p = Runtime.getRuntime().exec(commandToRun);
      p.waitFor();
      p.destroy();
    }
    catch (InterruptedException e1) {
      // waitFor() was interrupted
      System.out.println(e1);
    }
    catch (Exception e2) {
      // something else happened
      System.out.println(e2);
    }
  }
Technical Details
Message-ID: <34F5E42A.59835113@ForAWhile.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <01bd42ff$b99fe740$730aa8c0@devwjf>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,260c66719a6fac9e
X-Google-Attributes: gidf74b3,public
From: "James D. Frentress" <Broken@ForAWhile.com>
Subject: Re: JNI example requested
Date: 1998/02/26
Message-ID: <34F5E42A.59835113@ForAWhile.com>
X-Deja-AN: 328950368
Content-Transfer-Encoding: 7bit
References: <01bd42ff$b99fe740$730aa8c0@devwjf>
X-Priority: 3 (Normal)
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Organization: Microsoft
Newsgroups: borland.public.jbuilder.java.language