Hi All

My 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();
    }
}

I think it's because you're using the start command. This command actually asks Windows to execute the command and since you're using dir this will result in Windows opening up a command prompt. I advise you to simply remove the word start so that you only have runtime.exec("cmd /c dir"); . This would probably solve your problem though I might be mistaken...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.