GnuPG with Java waitFor() method on Windows?

Ruke Wang ruke@servgate.com
Tue Jul 29 04:01:01 2003


I am trying to use java Runtime.getRuntime().exec() to call gnupg to decrypt
encrypted file.  However, even though the file is properly decrypted,
waitFor() never returns.  The problem does not occur while I tried to verify
a signed data file.  By the way, is Java SDK1.4 Gnupg compatible?

Thanks,
Ruke Wang

Here is my code, quite simple:

import java.io.*;

public class LicenseXmlTest 
{
	public static void main(String[] args) 
	{
			TestXml tester = new TestXml();
			tester.Verify("d:\\test\\test.key");
	}
}

class TestXml 
{
	private String ExpireDate;

	private static String gpg_cmd = "c:\\gnupg\\gpg ";
	private static String home_dir = "--homedir d:\\test ";
	private static String key_ring = "--keyring ppp.asc --secret-keyring
sss.asc ";
	private static String decrypt_para = "--decrypt ";
	private static String output_para = "--output ";
	private static String license_file = "d:\\test\\test.txt ";
	
	public TestXml()
	{
		ExpireDate = new String("01/01/1970");
	}
	
	public boolean Verify(String infile)
	{
		try
		{
			String cmd = gpg_cmd + home_dir + key_ring +
output_para + license_file + decrypt_para + infile;
			Process opengpg = Runtime.getRuntime().exec(cmd);
			System.out.println(cmd);
			
			opengpg.waitFor();
			
			return true;
		}
		catch(IOException e)
		{
			System.err.println("Verify() ioexception" +
e.toString());
			return false;
		}
		catch (InterruptedException e) 
		{ 
			System.err.println("Verify() interrupt" +
e.toString());
			Thread.currentThread().interrupt();
			return false;
		}
	}
}