Execute an External Program Without Using JNI

The secret lies in the Runtime class. Runtime contains the methodexec, which takes the basic form of:

 Process exec(String command) orProcess exec(String[] comdarray) orProcess exec(String[] cmdarray, String[] envp, File dir)


Where command is the name of the executable, comdarray contains the exe name and arguments, envp contains the environment variables, and File contains the file name. exec returns the abstract object Process, whose getInputStream() and getOutputStream() can be used to collect I/O information on the running process.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: