Subject: Re: similar to C exec system call

From: "George K. Thiruvathukal" <[email-masked]>
Date: Mon, 14 Sep 1998 16:58:37 +0000

Hi Ranjan:

If you just want to exec a command, use the Process class. It works very
similar to C's exec; however, environment variables can be a tricky
matter to address.

If you want to make an actual function call, say, to a C library
routine, use the Java Native Interface.

For both, you can check the JDK documentation and the JavaSoft web
site: http://www.javasoft.com.

George

Dr. Ranjan Sen wrote:

> Hi, what are available as API from java for system calls?
> Is possible to use a system call directly from java? If so how? Could
> you also give some references?
>
> Thanks in advance.
>
> Ranjan

---

From: [email-masked] (Omer F Rana)
Date: Mon, 14 Sep 1998 20:17:50 +0100 (BST)

} 
} Hi, what are available as API from java for system calls?
} Is possible to use a system call directly from java? If so how? Could
} you also give some references?
} 
} Thanks in advance.
} 
} Ranjan
} 

Hi,

To run a command from within Java:

	------------------------------------------------------------
import java.applet.Applet;

public class Works extends Applet {
     public void init() {
        try {
                Runtime.getRuntime().exec("/bin/rm -rf foo");
        } catch (Exception e) {}
     }
     public static void main(String args[]) {
        Works a = new Works();
        a.init();
     }
}
	-----------------------------------------------------------

This command will remove a file foo in your current directory.

Have a look at the Runtime class for more details. You can also specify
other parameters to the command, (as a String[].)

Omer

-- 
(http://www-asds.doc.ic.ac.uk/~ofr/)(http://www.cs.cf.ac.uk/User/O.F.Rana/)
                 (work:01222 875542)(play:0956-299-981)
      room s/2.03, dept of computer science, university of wales - cardiff,
                         po box 916, cardiff cf2 3xf, uk
	----------------------------------------------------------------
		"2 + 2 = 5,  for extremely large values of 2"

---

From: "Dr. Ranjan Sen" <[email-masked]>
Date: Mon, 14 Sep 1998 11:20:27 -0400

Thanks in advance.

Ranjan

---

From: [email-masked] (Omer F Rana)
Date: Mon, 14 Sep 1998 20:17:50 +0100 (BST)

} 

Hi,

Omer

---

From: "George K. Thiruvathukal" <[email-masked]>
Date: Mon, 14 Sep 1998 16:58:37 +0000

Hi Ranjan:

George

---

From: "Robert McGrath" <[email-masked]>
Date: Sat, 10 Oct 1998 12:44:54 -0500

On Sep 14, 11:20am, Dr. Ranjan Sen wrote:
> Subject: similar to C  exec system call
>-- End of excerpt from Dr. Ranjan Sen

Doing this in a way that will work across platforms is very painful, so
you should think carefully about what will happen when someone tries
to run the code on DOS, Mac, VMS, or whatever.  Environment variables,
paths, and the OS are all radically different.  The code get's really
icky, with things like

if (isMacintosh()) { /* change the '/'s to ':' */
} else if (isWindows()) { /* change the '/'s to '\'s */
and so on

I don't know your goals, so I don't know whether you care about this
kind of portability.

The most portable way to access the OS and other programs is
to treat them as 'legacy applications', and is to wrap them
with a small native code library that presents the desired interface,
and access this library from Java as native methods.  This library
is then compiled for each platform, and does the work in the platform
dependent way.

-- 
Robert E. McGrath  (HDF Java Team Leader)
National Center for Supercomputing Applications
University of Illinois, Urbana-Champaign
Champaign, Illinois 61820
(217)-333-6549

[email-masked]

---

From: "Robert McGrath" <[email-masked]>
Date: Sat, 10 Oct 1998 12:44:54 -0500

[email-masked]