Results 1 to 3 of 3
- 06-23-2011, 01:21 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 1
- Rep Power
- 0
Runtime anc linux zip compression
Hello
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 '{}' \;
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;
thanks for any response
- 06-24-2011, 10:12 AM #2
I didn't test my solution but try to replace the single quote with \"
String command = "find /user/test -type f -exec zip \"{}\".zip \"{}\" \\:"
- 08-08-2011, 11:18 PM #3
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 8
@j2me64
Why would that work if it work as is in terminal?
@OP
I would try with
Java Code:String command[] = { "find" , "/home/user/test" , "-type", "f", "zip", "{}.zip", "{}", "\\;"}; //note that spaces and quotes are removed
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.
Edit:
Clarification:
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
-
BufferedInputStream with Huffman Compression
By Msnforum in forum New To JavaReplies: 0Last Post: 11-03-2009, 09:04 PM -
Problem with Runtime.getRuntime().exec with Linux Commands
By swapnilnawale in forum Threads and SynchronizationReplies: 1Last Post: 09-23-2009, 10:23 PM -
Compression Algorithms
By kishan in forum Advanced JavaReplies: 1Last Post: 09-21-2009, 09:13 AM -
compression in jboss
By appu in forum Advanced JavaReplies: 0Last Post: 07-07-2009, 01:17 AM -
Image Compression
By MarkWilson in forum New To JavaReplies: 6Last Post: 09-29-2008, 08:00 AM
Bookmarks