Results 1 to 5 of 5
  1. #1
    keshari is offline Member
    Join Date
    May 2008
    Posts
    7
    Rep Power
    0

    Default Problem during executing Command Prompt

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

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    I don't get what you are talking about...

    eg. Not clear for me....

    You mean, if some task executed, that program should not end? until such close command encounters?

    You may use do/while if it is.....
    freedom exists in the world of ideas

  3. #3
    keshari is offline Member
    Join Date
    May 2008
    Posts
    7
    Rep Power
    0

    Default

    Quote Originally Posted by sukatoa View Post
    I don't get what you are talking about...

    eg. Not clear for me....

    You mean, if some task executed, that program should not end? until such close command encounters?

    You may use do/while if it is.....

    Ok dear,do 1 thing just copy and paste the cod and then execute this 3 times,each time you will find new command prompt.Now I dont want more than one command prompt after every execution.Means after running the code a black window will appear,and when again execute that code again second black window will appear.I dont want the second black window,untill unless I did not close the first black window.

  4. #4
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    I never did that before....

    Here is an alternative idea,

    If you can trace whether a terminal/CMD is still on process through java, then, use it as a flag to represent that the said console is still on process....
    freedom exists in the world of ideas

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    You are asking some kine of annoying thing here. Each time you run the code, in simple word in create three reference variables. All are execute your code and open a command prompt for each instance.

    What you can do it, as sukatoa says, before executing your application again check that a command prompt is already open or not.

Similar Threads

  1. accessing command prompt using java (netbeans)...
    By kureikougaiji in forum New To Java
    Replies: 6
    Last Post: 06-27-2008, 04:01 PM
  2. Problem with executing
    By mcal in forum New To Java
    Replies: 2
    Last Post: 02-09-2008, 02:51 PM
  3. Problem with executing .jar files
    By hiranya in forum NetBeans
    Replies: 2
    Last Post: 10-02-2007, 08:24 PM
  4. Replies: 2
    Last Post: 08-06-2007, 10:16 PM
  5. Problem while executing programs
    By bks504 in forum New To Java
    Replies: 10
    Last Post: 08-02-2007, 02:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •