Jump to content

Problem during executing Command Prompt through java


Recommended Posts

Hi AllMy current code is executing system commands through java programme,like “dir”,”date” itc.Whenever I run the code the desired output comes.But when I am running the code continuselly then lots of command prompt open regularlly.Is there any way to stop the code from execution untill unless the command prompt get closed manually?Here is my code.import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.IOException;interface IPerlService{ public String BZMCreateZone(String s); public int BZMRenew();}public class Sample { public void BZMCreateZone() { Runtime runtime; Process process; String s=null; String str=null; try { runtime = Runtime.getRuntime(); process =runtime.exec("cmd /c start dir"); str=process.toString(); try { process.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); } BufferedReader reader = new BufferedReader( new InputStreamReader(process.getInputStream())); s = reader.readLine(); } catch (IOException ex) { ex.printStackTrace(); } } public static void main(String[] args) { Sample obj_Sample= new Sample(); obj_Sample.BZMCreateZone(); }}

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...