wood burning stoves 2.0*
The moose likes Java in General and the fly likes DOS command in java program question.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "DOS command in java program question.." Watch "DOS command in java program question.." New topic
Author

DOS command in java program question..

Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 260
hi,

I can delete the folder directly using DOS command from java program,


now I need to now how to remove a folder with the confirmation.

Here is in details.
1) apply rmdir <folder Name>
2) ask for confirmation Y/N
3) if Y, remove else keep it as it is

Can we do this from java program?


Thanks,
Kumar
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Yes, but wouldn't it be easier to do the deletion via the classes in the java.io package rather than using the the command shell?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 260
I tried with DEL command in DOS, it supports to delete files only with confirmation what I expected.
It supports to remove files only, look at this
then It prompts me to remove the file, Y, it is

Ok later I used the same command to remove a file with java program

the console process is still going for longer, it never stopped to display the results. I don't know what's going with this.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18136
    
  39

I agree with Paul. Would it not be easier to use the classes in the java.io package?


Furthermore, by going this route, you won't be platform independent anymore -- the application would require the DOS commands. With the java.io package, it would work on any platform supported by Java.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

But why? What does the console give you which you need over and above IO via Java? It seems you are possibly creating work for yourself.
Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 260
Please look at the code below, I Used java.io package, but I don't get what you are suggesting with that


while executing the above code, When the controller comes to stdInput.readLine() (To display the output), the process is struck and cannot move from there.
I blocked the while loop and executed, the process is done but file is not deleted.

Could you please suggest me with your java.io knowledge how to del file/folder?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18136
    
  39

Kumar Kuchipudi wrote:Could you please suggest me with your java.io knowledge how to del file/folder?


We mean something like...



Henry
Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 260
Wang,

I know with that, but we are having a requirement to remove them through DOS commands executing from java program.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18136
    
  39

Kumar Kuchipudi wrote:I know with that, but we are having a requirement to remove them through DOS commands executing from java program.


Why didn't you just say so? We kept asking you why you were doing something so silly, and you just ignored it, which peaked our interest.

Well... good luck. Hopefully, someone did something similar.

Henry
Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 260
Hi wang,

I thought you have different idea with java.io, thats why I was waiting for the result from you. I'm not in that way what you think. I dont know why feel angry on this moment.

Thanks from your time.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18136
    
  39

I dont know why feel angry on this moment.


I am not angry. Am I coming across as such? Hmmm.... Don't know why. My friends sometimes say the same thing.

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DOS command in java program question..
 
Similar Threads
String format to create directory in Unix
Difficulty in understanding the the way the code is compiled in the book
Deleting a Folder or dir which contain more than 10K subfolders
Can any please advise me on how to run the java file using command prompt?
Java Beginner