File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes the question about copy files in unix use Runtime.exec? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "the question about copy files in unix use Runtime.exec?" Watch "the question about copy files in unix use Runtime.exec?" New topic
Author

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

alex han
Ranch Hand

Joined: Dec 13, 2002
Posts: 46
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

Joined: Jul 08, 2003
Posts: 24166
    
  30

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".


[Jess in Action][AskingGoodQuestions]
alex han
Ranch Hand

Joined: Dec 13, 2002
Posts: 46
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

Joined: Jul 08, 2003
Posts: 24166
    
  30

"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

Joined: Dec 13, 2002
Posts: 46
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

Joined: Mar 19, 2002
Posts: 405
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: the question about copy files in unix use Runtime.exec?
 
Similar Threads
Runtime.getRuntime() help plzzzzzzzz
Runtime.exec().
Runtime.exec problem
Help needed with in executing a UNIX script from Java
putenv ?