• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

del command with Runtime.exec()

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try
[code]
String command="cmd /c del c:\test\*.txt ";
[\code]
 
Ranch Hand
Posts: 382
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic