Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-04-2008, 04:07 PM
Member
 
Join Date: May 2008
Posts: 7
keshari is on a distinguished road
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();
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-04-2008, 04:12 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
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.....
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-04-2008, 04:48 PM
Member
 
Join Date: May 2008
Posts: 7
keshari is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-04-2008, 07:25 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
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....
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-05-2008, 06:06 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 5,075
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
accessing command prompt using java (netbeans)... kureikougaiji New To Java 6 06-27-2008 05:01 PM
Problem with executing mcal New To Java 2 02-09-2008 03:51 PM
Problem with executing .jar files hiranya NetBeans 2 10-02-2007 09:24 PM
problem when I try to compile a program from command prompt osval Advanced Java 2 08-06-2007 11:16 PM
Problem while executing programs bks504 New To Java 10 08-02-2007 03:32 PM


All times are GMT +3. The time now is 12:04 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org