Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Brayden Smith   on Feb 04 In Java Category.

  
Question Answered By: Myrna Brown   on Feb 04

I faced this problem  some time ago, but the solution Mr.HaghighatKhah recommended (and also using class "ProcessBuilder") does not work for all the commands  executed in cmd environment.
for instance consider the command  "copy d:\music\someFile.txt d:\downloads"
executed in cmd environment correctly, but when running the following code you'll notified the occurrence of this exception : "Exception in thread "main" java.io.IOException: Cannot run program "copy": CreateProcess error=2, The system cannot find the file  specified"


<code>


String cmd = "copy d:\\music\\someFile.txt d:\\downloads";
try {
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
e.printStackTrace();
}


</code>

Share: 

 

This Question has 4 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on copy with command prompt Or get search suggestion and latest updates.


Tagged: