+ progress (_ ("Running `%s' on file `%s' to detect default page settings.\n")
+ % (global_options.latex_program, tmpfile))
+ cmd = '%s %s' % (global_options.latex_program, tmpfile)
+ debug ("Executing: %s\n" % cmd)
+ run_env = os.environ.copy()
+ run_env['LC_ALL'] = 'C'
+ run_env['TEXINPUTS'] = '%s:%s' % \
+ (global_options.input_dir, run_env.get('TEXINPUTS',""))
+
+ ### unknown why this is necessary
+ universal_newlines = True
+ if sys.platform == 'mingw32':
+ universal_newlines = False
+ ### use os.system to avoid weird sleep() problems on
+ ### GUB's python 2.4.2 on mingw
+ # make file to write to
+ output_dir = tempfile.mkdtemp()
+ output_filename = os.path.join(output_dir, 'output.txt')
+ # call command
+ cmd += " > %s" % output_filename
+ oldtexinputs = os.environ.get ('TEXINPUTS')
+ os.environ['TEXINPUTS'] = run_env['TEXINPUTS']
+ returncode = os.system(cmd)
+ if oldtexinputs:
+ os.environ['TEXINPUTS'] = oldtexinputs
+ else:
+ del os.environ['TEXINPUTS']
+ parameter_string = open(output_filename).read()
+ if returncode != 0:
+ warning (_ ("Unable to auto-detect default settings:\n"))
+ # clean up
+ os.remove(output_filename)
+ os.rmdir(output_dir)
+ else:
+ proc = subprocess.Popen (cmd,
+ env=run_env,
+ universal_newlines=universal_newlines,
+ shell=True,
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ (parameter_string, error_string) = proc.communicate ()
+ if proc.returncode != 0:
+ warning (_ ("Unable to auto-detect default settings:\n%s")
+ % error_string)