Skip to content

Commit 1bab3c7

Browse files
committed
Remove precmd from backend_ps and use subprocess
1 parent 2058dcb commit 1bab3c7

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

lib/matplotlib/backends/backend_ps.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -1458,20 +1458,17 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
14581458
"rcParam.", 'helpful')
14591459
raise
14601460

1461-
# the split drive part of the command is necessary for windows users with
1462-
# multiple
1463-
if sys.platform == 'win32': precmd = '%s &&'% os.path.splitdrive(tmpdir)[0]
1464-
else: precmd = ''
14651461
#Replace \\ for / so latex does not think there is a function call
14661462
latexfile = latexfile.replace("\\", "/")
14671463
# Replace ~ so Latex does not think it is line break
14681464
latexfile = latexfile.replace("~", "\\string~")
1469-
command = '%s cd "%s" && latex -interaction=nonstopmode "%s" > "%s"'\
1470-
%(precmd, tmpdir, latexfile, outfile)
1465+
command = [str("latex"), "-interaction=nonstopmode",
1466+
'"%s"' % latexfile]
14711467
verbose.report(command, 'debug')
14721468
try:
1473-
output = subprocess.check_output(command, shell=True,
1474-
stderr=subprocess.STDOUT)
1469+
with open(outfile, "w") as fout:
1470+
subprocess.check_call(command, cwd=tmpdir,
1471+
stdout=fout, stderr=subprocess.STDOUT)
14751472
except subprocess.CalledProcessError as exc:
14761473
with io.open(outfile, 'rb') as fh:
14771474
raise RuntimeError('LaTeX was not able to process your file: '
@@ -1482,12 +1479,13 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
14821479
verbose.report(fh.read(), 'debug')
14831480
os.remove(outfile)
14841481

1485-
command = '%s cd "%s" && dvips -q -R0 -o "%s" "%s" > "%s"'%(precmd, tmpdir,
1486-
os.path.split(psfile)[-1], os.path.split(dvifile)[-1], outfile)
1482+
command = [str('dvips'), '-q', '-R0', '-o', os.path.basename(psfile),
1483+
os.path.basename(dvifile)]
14871484
verbose.report(command, 'debug')
14881485
try:
1489-
output = subprocess.check_output(command, shell=True,
1490-
stderr=subprocess.STDOUT)
1486+
with open(outfile, "w") as fout:
1487+
subprocess.check_call(command, cwd=tmpdir,
1488+
stdout=fout, stderr=subprocess.STDOUT)
14911489
except subprocess.CalledProcessError as exc:
14921490
with io.open(outfile, 'rb') as fh:
14931491
raise RuntimeError('dvips was not able to process the following '

0 commit comments

Comments
 (0)