• Post Reply Bookmark Topic Watch Topic
  • New Topic

error running cmd command in Java  RSS feed

 
Eduardo Ponce de Leon
Ranch Hand
Posts: 99
  • 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...
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java 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: 99
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!