exit code on windows

Mark McEahern marklists at mceahern.com
Tue Dec 9 23:30:19 EST 2003


Is there a straightforward way to get the exit code from a windows
process?

I want to write a script that runs a bunch of .sql files against SQL
Server using osql.  I want it to stop if there's an error; e.g.,

  import os
  import glob

  server = 'foo'
  database = 'bar'
  template = 'osql -s%(server)s -d%(database)s -f%(name)s'
  for name in glob.glob('*.sql'):
    cmd = template % locals()
    stdin, stdout = os.popen2(cmd)
    output = stdout.read()
    print stdin.close()
    print stdout.close()
    # On Unix I'd use the return value from the fd.close()
    # to get the exit code, but on Windows the return values
    # here are:
    #   None
    #   None

Does that mean the way I'd get the exit code on Unix has no hope of
working on Windows?

Thanks,

// m






More information about the Python-list mailing list