aspose file tools*
The moose likes Beginning Java and the fly likes del command with Runtime.exec() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "del command with Runtime.exec() " Watch "del command with Runtime.exec() " New topic
Author

del command with Runtime.exec()

prachi jahagirdar
Greenhorn

Joined: Feb 02, 2004
Posts: 11
hello,
I was trying to run the DOS command 'del' using Runtime.exec().
Other commands work properly.
I have the files in respective folders which are to be deleted.
My code look like this
String command="del c:\test\*.txt ";
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(command);
Output is
java.io.IOException: CreateProcess: del c:\abc\test\*.txt error=0
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:67)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:566)
at java.lang.Runtime.exec(Runtime.java:428)
at java.lang.Runtime.exec(Runtime.java:364)
at java.lang.Runtime.exec(Runtime.java:326)
at CreatePatch.runcommand(CreatePatch.java:161)
at CreatePatch.getVector(CreatePatch.java:144)
at CreatePatch.main(CreatePatch.java:26)
Nischal Topno
Ranch Hand

Joined: Nov 24, 2001
Posts: 45
try
[code]
String command="cmd /c del c:\test\*.txt ";
[\code]
Sadanand Murthy
Ranch Hand

Joined: Nov 26, 2003
Posts: 382
Originally posted by prachi jahagirdar:
hello,
I was trying to run the DOS command 'del' using Runtime.exec().
Other commands work properly.
I have the files in respective folders which are to be deleted.
My code look like this
String command="del c:\test\*.txt ";
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(command);
Output is
java.io.IOException: CreateProcess: del c:\abc\test\*.txt error=0
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:67)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:566)
at java.lang.Runtime.exec(Runtime.java:428)
at java.lang.Runtime.exec(Runtime.java:364)
at java.lang.Runtime.exec(Runtime.java:326)
at CreatePatch.runcommand(CreatePatch.java:161)
at CreatePatch.getVector(CreatePatch.java:144)
at CreatePatch.main(CreatePatch.java:26)

This is because del is a built in command of the command.com/cmd.exe shell. To execute such commands you have to invoke cmd.exe or command.com and pass it the del command as the argument.
Read this article.


Ever Existing, Ever Conscious, Ever-new Bliss
 
 
subject: del command with Runtime.exec()