I am looking to open up a command prompt and pass in a copy command, some switches, and the source file plus destination. I’ve tried the code below but nothing appears to be happening. What am I not seeing? What could I be doing wrong?
String line; line = 'cmd COPY /Y C:\srcfolder\112.bin C:\destfolder'; Process p = Runtime.getRuntime().exec(line); p.waitFor();
If you really have to use an external command, then you probably want to execute (notice the /C):
I recommend you use the array version of
execto avoid handling of quoting (should any files or directories contain spaces – or double-quotes – in them):Remember that this is not portable (will not work on Unix), so unless you really really need to use
COPYthen you should use the method linked to bybstpierre.