public static void doDecrypt(String source,String dest ){
Runtime rt = Runtime.getRuntime();
GPGDecrypt rte = new GPGDecrypt();
Process proc;
StreamWrapper error, output = null ;
try {
proc = rt.exec("gpg --output "+dstfile +" --batch --passphrase "+ResourcePropertyManager.get("Passphrase")+ " --decrypt "+srcfile);
System.out.println("After Passing");
error = rte.getStreamWrapper(proc.getErrorStream(), "ERROR");
output = rte.getStreamWrapper(proc.getInputStream(), "OUTPUT");
int exitVal = 0;
error.start();
output.start();
error.join(3000);
output.join(3000);
exitVal = proc.waitFor();
System.out.println("Output: " + output.message + "\nError: "+ error.message);
} catch (IOException e) {
System.out.println("IO "+e.getMessage());
e.printStackTrace();
} catch (InterruptedException e) {
System.out.println("IEX"+e.getMessage());
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
rt = null;
rte = null;
proc = null;
error = null;
output = null;
}
}
在通过上面的代码动态传递值时,不会生成输出文件。
我在Windows中运行它。