aspose file tools
The moose likes Java in General and the fly likes Exception in System (Runtime) execute command for copying the file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Exception in System (Runtime) execute command for copying the file" Watch "Exception in System (Runtime) execute command for copying the file" New topic
Author

Exception in System (Runtime) execute command for copying the file

ranch ravi
Greenhorn

Joined: Jul 05, 2006
Posts: 2
Can any one tell me what is wrong with this - it throws an IOException

String sourcepath = "C:"+File.separator+"pbx"+File.separator+"mantra"+File.separator+"vvvvv.mp3";
String destinationpath = "C:"+File.separator+"rrr"+File.separator+"mantra"+File.separator+"mantra.mp3";
Runtime rt=Runtime.getRuntime();
try{
String command="C:"+File.separator+"windows"+File.separator+"command /c copy "+sourcepath+" "+destinationpath;
System.out.println(command);
rt.exec(command);
}catch(IOException ex){System.out.println("exception "+ex); ex.printStackTrace();}

output:-
C:\windows\command /c copy C:\pbx\mantra\vvvvv.mp3 C:\rrr\mantra\mantra.mp3
exception java.io.IOException: CreateProcess: C:\windows\command /c copy C:\pbx\mantra\vvvvv.mp3 C:\
rrr\mantra\mantra.mp3 error=2
java.io.IOException: CreateProcess: C:\windows\command /c copy C:\pbx\mantra\vvvvv.mp3 C:\rrr\mantra
\mantra.mp3 error=2
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:66)
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 Test.main(Test.java:82)
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14672
    
  11

instead of command, did you try with "cmd /c copy" ?


[My Blog]
All roads lead to JavaRanch
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14672
    
  11

and check this out:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
ranch ravi
Greenhorn

Joined: Jul 05, 2006
Posts: 2
not find the solution. plz help..
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"ranch ranch",

Welcome to the Ranch.

We're a friendly bunch, but we take display names seriously. Display names must two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile since accounts with invalid display names get deleted.

thanks,
Dave.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Exception in System (Runtime) execute command for copying the file
 
Similar Threads
Running DOS commands
using windows command line to copy and paste. getting file not found error
problem in copying files from/to different machines using java
running OS commands in Java
Runtime.exec()