ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

How will you invoke any external process in Java?

user-image
تم إضافة السؤال من قبل Mohd shahnawaz khan , Associate Project , Cognizant Technology Solution
تاريخ النشر: 2014/04/16
Mufeed Farhan
من قبل Mufeed Farhan , HR Applications Manager , SBM

We can invoke the external process in Java using exec() method of Runtime Class .

 

Example Below:

import java.io.*;

public class Main

{      

public static void main(String args[])

{           

try {               

Runtime rt = Runtime.getRuntime();               

Process pr = rt.exec("c:\\\\helloworld.exe");               

BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));               

String line=null;               

while((line=input.readLine()) != null)

{                    System.out.println(line);               

               int exitVal = pr.waitFor();               

System.out.println("Exited with error code "+exitVal);           

} catch(Exception e)

{               

System.out.println(e.toString());               

e.printStackTrace();           

}        }}

 

Copied From:

http://www.javaken.com/forum/showthread.php?t=2749 .

 

yahia dekar
من قبل yahia dekar , ingenieur d'etat en informatique , universite djilali liabbes - sidi bel abbes

exec