Results 1 to 5 of 5
  1. #1
    hari.kr is offline Member
    Join Date
    Feb 2010
    Posts
    8
    Rep Power
    0

    Default Trigger cmd to delete a file in java program

    Hi everyone,
    I want to trigger cmd.exe with the parameters as "del \"webapps/Example-App/WEB-INF/files/users.xml". Can anyone suggest me some solution how to do this ?

    If I trigger "del \"webapps/Example-App/WEB-INF/files/users.xml", I got some error

    java.io.IOException: CreateProcess: del.exe "webapps/Example-App/WEB-INF/files/users.xml" error=2
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
    at java.lang.ProcessImpl.start(ProcessImpl.java:30)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java :451)
    at java.lang.Runtime.exec(Runtime.java:591)
    at java.lang.Runtime.exec(Runtime.java:429)
    at java.lang.Runtime.exec(Runtime.java:326)
    at com.io.IOFileOperation.removeFile(IOFileOperation. java:316)
    at com.io.IOFileOperation.remove(IOFileOperation.java :306)
    at com.io.IOFileOperation.editXmlFile(IOFileOperation .java:103)
    at com.io.IOManager.editData(IOManager.java:36)
    at com.home.EditUserServlet.doPerform(EditUserServlet .java:44)
    at com.home.EditUserServlet.doPost(EditUserServlet.ja va:24)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,340
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by hari.kr View Post
    Hi everyone,
    I want to trigger cmd.exe with the parameters as "del \"webapps/Example-App/WEB-INF/files/users.xml". Can anyone suggest me some solution how to do this ?

    If I trigger "del \"webapps/Example-App/WEB-INF/files/users.xml", I got some error

    java.io.IOException: CreateProcess: del.exe "webapps/Example-App/WEB-INF/files/users.xml" error=2
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
    at java.lang.ProcessImpl.start(ProcessImpl.java:30)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java :451)
    at java.lang.Runtime.exec(Runtime.java:591)
    at java.lang.Runtime.exec(Runtime.java:429)
    at java.lang.Runtime.exec(Runtime.java:326)
    at com.io.IOFileOperation.removeFile(IOFileOperation. java:316)
    at com.io.IOFileOperation.remove(IOFileOperation.java :306)
    at com.io.IOFileOperation.editXmlFile(IOFileOperation .java:103)
    at com.io.IOManager.editData(IOManager.java:36)
    at com.home.EditUserServlet.doPerform(EditUserServlet .java:44)
    at com.home.EditUserServlet.doPost(EditUserServlet.ja va:24)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    If I'm not mistaken 'del' isn't a separate command but it's handled by the cmd.exe shell itself. Instead try to exec this:"cmd -c del \"webapps/Example-App/WEB-INF/files/users.xml"

    kind regards,

    Jos

  3. #3
    hari.kr is offline Member
    Join Date
    Feb 2010
    Posts
    8
    Rep Power
    0

    Default Trigger cmd to delete a file in java program

    Hi Jos thanks for the reply.
    I tried the command you have given but it's not working.

    Regards
    Harry

  4. #4
    hari.kr is offline Member
    Join Date
    Feb 2010
    Posts
    8
    Rep Power
    0

    Default Trigger cmd to delete a file in java program

    Hi Jos,

    Thanks again. It works but it's '/c' not -c as you have given. Thanks for the clue.

    Regards,
    Harry

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,340
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by hari.kr View Post
    Hi Jos,

    Thanks again. It works but it's '/c' not -c as you have given. Thanks for the clue.
    Sorry for the mistake; my unixism is showing through ;-) Glad you solved it.

    kind regards,

    Jos

Similar Threads

  1. generating trigger using java
    By money3 in forum JDBC
    Replies: 1
    Last Post: 10-06-2009, 11:56 AM
  2. Oracle trigger interacting with Java app
    By KentDMc in forum Advanced Java
    Replies: 1
    Last Post: 04-27-2009, 01:49 AM
  3. delete a line from a text file in Java
    By ddatta8 in forum New To Java
    Replies: 2
    Last Post: 01-24-2009, 05:08 AM
  4. Replies: 1
    Last Post: 11-10-2008, 09:49 AM
  5. Replies: 1
    Last Post: 08-07-2007, 07:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •