Results 1 to 3 of 3
  1. #1
    lukasw44 is offline Member
    Join Date
    Jun 2011
    Rep Power

    Default Runtime anc linux zip compression

    i hava task and i must using linux command zip (not java.library zip or other )
    in my program user send parameter path to the directory and program must zip all files in this subdirectory

    so i write this command in linux:

    XML Code:
    find /home/user/test -type f -exec zip '{}'.zip '{}' \;
    and its work very god

    but i have problem write it in java i use
    String command = "find /user/test -type f -exec zip '{}'.zip '{}' \\:"
    Process p = Runtime.getRuntime.exec(command)

    but i have got error because cannot use exec in exec so i thing to use second type of function exec(command[], env[]);

    but i donto know how write this function :/

    i wrote something like this:
    Java Code:
    String command[] = { "find" , " /home/user/test" , " -type f" , " zip '{}'.zip '{}' \\;"};
    String exec[] = null;
    but its not working so please help how can i write this command in exec ???

    thanks for any response

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Zurich, Switzerland
    Rep Power


    I didn't test my solution but try to replace the single quote with \"

    String command = "find /user/test -type f -exec zip \"{}\".zip \"{}\" \\:"

  3. #3
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Stockholm, Sweden
    Blog Entries
    Rep Power


    Why would that work if it work as is in terminal?

    I would try with
    Java Code:
    String command[] = { "find" , "/home/user/test" , "-type", "f", "zip", "{}.zip", "{}", "\\;"}; //note that spaces and quotes are removed
    But since you do not have any spaces in quotes it may be more readable if you use
    Java Code:
    String command[] = "find /home/user/test -type f zip {}.zip {} \\;".split(" "); //If you were to use spaces inside the quotes, you could change split's parameter, it is in regular expression.

    Each element in the string list is an argument given to the started program, just as putting it in quotes in the terminal (or escaping spaces).
    Quotes in a string is Java is as \' (or \") in the terminal, they become escaped.
    Last edited by Hibernate; 08-08-2011 at 11:24 PM. Reason: no single quotes
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

Similar Threads

  1. BufferedInputStream with Huffman Compression
    By Msnforum in forum New To Java
    Replies: 0
    Last Post: 11-03-2009, 10:04 PM
  2. Problem with Runtime.getRuntime().exec with Linux Commands
    By swapnilnawale in forum Threads and Synchronization
    Replies: 1
    Last Post: 09-23-2009, 10:23 PM
  3. Compression Algorithms
    By kishan in forum Advanced Java
    Replies: 1
    Last Post: 09-21-2009, 09:13 AM
  4. compression in jboss
    By appu in forum Advanced Java
    Replies: 0
    Last Post: 07-07-2009, 01:17 AM
  5. Image Compression
    By MarkWilson in forum New To Java
    Replies: 6
    Last Post: 09-29-2008, 08:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts