Skip to content

Instantly share code, notes, and snippets.

@finsterthecat
Created April 23, 2013 21:00
Show Gist options
  • Save finsterthecat/5447349 to your computer and use it in GitHub Desktop.
Save finsterthecat/5447349 to your computer and use it in GitHub Desktop.
package ca.ontario.moh.stix.loadfile;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Decrypt file using 7zip
*
*/
public class App {
public static void main(String[] args) throws IOException, InterruptedException {
if (args.length != 2) throw new IllegalArgumentException("usage: program file password");
Runtime r = Runtime.getRuntime();
Process p = r.exec("\"c:\\Program Files\\7-Zip\\7z.exe\" x -so " + args[0] + " -p" + args[1]);
BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader e = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String line;
System.out.println("\n\nFile Contents:\n");
while ((line = b.readLine()) != null) {
System.out.println(line);
}
System.out.println("\n\nErrors:\n");
while ((line = e.readLine()) != null) {
System.out.println(line);
}
p.waitFor();
}
}
@finsterthecat
Copy link
Author

Not pretty but simple and it works. Reading the crypto docs was giving me a major headache!

@finsterthecat
Copy link
Author

OK, checked out winzipaes and ran the tests successfully. Going with that as superior solution. This is still decent example for executing runtime and capturing sysout, syserr in a java program should I ever feel the need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment