File Access Issues with File creation

Ok, for all you Certificate Gurus, here is a bizarre one for you!

I am downloading a .pfx (PKCS12) file to a local file. I then use a System
call to run a Java application I have written to convert that PKCS12 file
into a pem (I essentially am just getting rid of the password protection).
Upon finishing the system call, I then attempt to open this file with the
OpenSSL::X509:: Certificate.new call. This produces the following error:
   OpenSSL::X509::CertificateError: not enough data
      Y:/pki/../lib/pkistdlib.rb:346:in `initialize'
      Y:/pki/../lib/pkistdlib.rb:349:in `join'
      Y:/pki/../lib/pkistdlib.rb:349:in `validateExportedCert'
      Y:/pki/../lib/pkistdlib.rb:349:in `each'
      Y:/pki/../lib/pkistdlib.rb:349:in `validateExportedCert'
      Y:/pki/../lib/pkistdlib.rb:323:in `check_Export_WprivateKey'
      Y:/pki/../lib/pkistdlib.rb:284:in `times'
      Y:/pki/../lib/pkistdlib.rb:284:in `check_Export_WprivateKey'
      Y:/pki/eval/pki_validation.rb:37:in `test_02_ExportKMO_validate'
      Y:/pki/../lib/testcase_impl.rb:26:in `run'

The interesting part is this. I can stall the progress, with a gets
command, and use the exact same code run from a different file, and read the
exact same certificate file with no problem. Any ideas as to why this is
happening?

Thanks in advance!

Mbright

Code:
  Ruby Ceritifcate Code:

    require 'openssl'
    file=File.open(out)
    cert=OpenSSL::X509::Certificate.new(file.read) if file &&
FileTest::file?(file)
    file.close()

  Java Code is cleaning up with System.exit();

Make sure the Java code is flushing the streams; System.exit() won't
do it for you.

···

On 10/2/06, Michael Bright <michael.bright@gmail.com> wrote:

Ok, for all you Certificate Gurus, here is a bizarre one for you!

--
Contribute to RubySpec! @ Welcome to headius.com
Charles Oliver Nutter @ headius.blogspot.com
Ruby User @ ruby.mn

Make sure the Java code is flushing the streams; System.exit() won't

do it for you.

Thanks for advice, I am using a FileOutputStreamWriter and I am calling the
flush and close prior to calling System.exit(). I should have stated that
in the previous section.