Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

del command with Runtime.exec()

 
prachi jahagirdar
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try
[code]
String command="cmd /c del c:\test\*.txt ";
[\code]
 
Sadanand Murthy
Ranch Hand
Posts: 382
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic