• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

error running cmd command in Java

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to "copy" or "xcopy" a file from my hard drive to a network drive that I have mapped. My string is not working in java but it does when I input the line directly in cmd.

Can somebody guide me on how to form the string in order for it to work in java...

this is my code


this is in main()


this is my function



The output of this is .....
"0 File(s) copied"

if I input this in cmd, it works with no problem

PLEASE HELP as I been struggling with this for several hours and have tried many things...
 
Sheriff
Posts: 21758
102
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you try to copy a non-existing file or folder, then an error message will be printed to stderr and the "0 File(s) copied" message to stdout. You only read the latter, so I've got a feeling that your file doesn't exist.

I suggest you stop using Runtime.getRuntime().exec and start using ProcessBuilder. It's a great improvement over the former, as it allows you to better split your command line arguments and also (and this is important for you) allows you to merge the error output with the standard output.
 
Eduardo Ponce de Leon
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob,

Thanks for the reply...the path written before was correct, the file exists.


I have tried what you mention with ProcessBuilder and I am not getting any lucky.



I can just open the file directly or if not I get this error..

"Windows cannot find 'Combined'. Make sure you typed the name correctly, and then try again.

I am sure it has to do something with spaces

If I just run a simple command like 'dir' I have no problem.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!