🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: are java system calls possible?

#16653
From: John Lacey
Date: Mon, 08 Feb 1999 00:00
29 lines
1719 bytes
"Steve Schafer (TeamB)" wrote:
> 
> On Mon, 08 Feb 1999 08:53:20 -0500, Rody Cunningham
> <rodycunningham@lucent.com> wrote:
> 
> >Is there any way to make a system call from a Java application?  I would
> >like to execute an external program, much the same way you can with the
> >"system" command in C.
> 
> Yes; you need to use native methods.

To call a native function you need to use native methods. 

To just run an external program, like system does, you can use
Runtime.exec(). It works mostly like the system function, but it
doesn't wait for the process to exit (you need to use the waitFor
method if you want that behavior), and for input and output there
are getInputStream and getOutputStream methods. See the examples
in any decent book on Java. (Interestingly, the Java Tutorial
shuns the topic.)

It's worth pointing out that using Runtime.exec() is likely to
make your program non-portable. (I'm not positive whether, like
native methods, it automatically makes your program less than
100% pure Java, but I suspect it does.)

John L

cc: Rody Cunningham
Technical Details
Message-ID: <36BF58BF.C3676198@vizdom.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <36BEEC4F.2775AE4E@lucent.com> <36e50370.45076382@90.0.0.40>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,6e112df30c27e569
X-Google-Attributes: gidf74b3,public
From: John Lacey <johnl@vizdom.com>
Subject: Re: are java system calls possible?
Date: 1999/02/08
Message-ID: <36BF58BF.C3676198@vizdom.com>
X-Deja-AN: 442143279
Content-Transfer-Encoding: 7bit
References: <36BEEC4F.2775AE4E@lucent.com> <36e50370.45076382@90.0.0.40>
To: Rody Cunningham <rodycunningham@lucent.com>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: Vizdom Software, Inc.
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language