Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

the question about copy files in unix use Runtime.exec?

 
alex han
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am not familiar with the unix platform,but now i need copy files in unix use java's Runtime.exec.
in windows , i use



but in unix ,how can i do it?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not use pure Java code on all platforms?

But if you're determined to do this this way, the best UNIX equivalent of "cmd.exe /c start copy" is simply "cp".
 
alex han
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
Why not use pure Java code on all platforms?

But if you're determined to do this this way, the best UNIX equivalent of "cmd.exe /c start copy" is simply "cp".


many thanks,but what is the equivalent of "cmd.exe /c start" ?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"cmd.exe /c" means "run the command shell and execute the following command". "start" means, again, I believe, just "run the following command." And since "copy" is a shell built-in, at least the "cmd /c" is needed.

In UNIX, "cp" is an executable, and you can just execute it. "cp" is all you need. If you actually needed to run a shell, and have the shell run "cp", you could say

/bin/sh -c "cp file1 file2"

But as I said, you don't need to do that.
 
alex han
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
"cmd.exe /c" means "run the command shell and execute the following command". "start" means, again, I believe, just "run the following command." And since "copy" is a shell built-in, at least the "cmd /c" is needed.

In UNIX, "cp" is an executable, and you can just execute it. "cp" is all you need. If you actually needed to run a shell, and have the shell run "cp", you could say

/bin/sh -c "cp file1 file2"

But as I said, you don't need to do that.


yeah,it is very helpful,now i have understood, thanks
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would also recommend using the "man" manual pages for the "cp" command. There is difference in the syntax between coping a file and coping a directory structure using the command "cp".

At the command prompt on the unix system, just type:

[ November 21, 2005: Message edited by: Craig Jackson ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic