• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using windows command line to copy and paste. getting file not found error

 
john bullwinkle
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm needing to copy and paste + rename a file from one dir to another. i tried doing it in strictly java code, i was successful, but when opening the file, it is corrupt. so i decided to switch my method to just pass a copy line to the windows command line. i have successfully ran the copy line in the windows command prompt, however am getting an error in my code when doing it. here is the code



here is the output i'm getting

copy = COPY "C:\serviceTech\config\Tech\LPEquipmentLease_distributed.pdf" "C:\serviceTech\CompletedForms\ItemLPEqpLsetest_test_test.pdf"
java.io.IOException: Cannot run program "COPY": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at java.lang.Runtime.exec(Runtime.java:593)
at java.lang.Runtime.exec(Runtime.java:431)
at java.lang.Runtime.exec(Runtime.java:328)
at servicetech.SelectionScreen.getFileNames(SelectionScreen.java:338)

if i copy everything after the 'copy =' line into the command line, it works fine. so i'm unsure why i'm getting this cannot find the file specified.

thanks in advance for your help.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, John!

COPY is not an application; it's a built-in command of CMD.EXE. You'll need to run that using the /C flag. Run CMD /? for more info.

But I'd first investigate why the files became corrupted. Can you show us the old Java copy code?
 
john bullwinkle
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the help. not sure if i fully understand the way i should format the line.

i tried this:


it runs, however doesn't copy the file.

here is the original code i used to copy. option1-3 is strings from user input



 
john bullwinkle
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nvm. i forgot to put the /c flag in there.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please avoid abbreviations like "nvm".
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And before we forget, When Runtime.exec() won't.
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use Execlibrary from the Apache Commons. Its pretty handy utility for running external programs from Java.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic