wood burning stoves 2.0*
The moose likes Linux / UNIX and the fly likes ProcessBuilder Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "ProcessBuilder Issue" Watch "ProcessBuilder Issue" New topic
Author

ProcessBuilder Issue

vivek dhiman
Ranch Hand

Joined: Aug 05, 2011
Posts: 111

Hi

Below is my code that i am using to copy file from one location to another in linux environment.

Getting not any exception, but file is not getting copy at tgtPath. Please Advice if anything missing here.
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1035
    
  10

Since you are not using a shell to execute 'cp' you need to provide the full path to the 'cp' executable e.g. "/bin/cp" BUT BUT BUT you are falling for 3 of the traps outlined in http://www.javaworld.com/jw-12-2000/jw-1229-traps.html . You are not handling the process 'stderr' , you are not handling the process 'stdout' and you are ignoring the process return code. Although the 'traps' article is very old and deals with Runtime.exec() the recommendations still apply and you should follow them to the letter.

Why are you resorting to using ProcessBuilder to copy a file? It is very easy in pure Java.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ProcessBuilder Issue
 
Similar Threads
ProcessBuilder Constructor
how to finish the process forcibly?
Input redirection in Java
GUI update.
Catching InputStream from Runtime/Process