devxlogo

Execute an External Program Without Using JNI

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.

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist