You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pls consider using subprocess.PIPE instead of out_file and err_file #161
--- /home/user/Desktop/pythontex2.py 2019-12-14 04:27:04.718269040 +0300+++ /usr/share/texlive/texmf-dist/scripts/pythontex/pythontex2.py 2019-12-14 04:15:23.189530900 +0300@@ -1510,8 +1510,8 @@
basename = key_run.replace('#', '_')
out_file_name = os.path.expanduser(os.path.normcase(os.path.join(outputdir, basename + '.out')))
err_file_name = os.path.expanduser(os.path.normcase(os.path.join(outputdir, basename + '.err')))
- out_file = open(out_file_name, 'w', encoding=encoding)- err_file = open(err_file_name, 'w', encoding=encoding)+ out_file = subprocess.PIPE+ err_file = subprocess.PIPE
script = os.path.expanduser(os.path.normcase(os.path.join(outputdir, basename)))
if os.path.isabs(script):
script_full = script
@@ -1550,11 +1550,11 @@
else:
raise
- proc.wait()+ out_data, err_data = proc.communicate()
if proc.returncode != 0:
break
- out_file.close()- err_file.close()+ with open(out_file_name, 'wb') as out_file: out_file.write(out_data)+ with open(err_file_name, 'wb') as err_file: err_file.write(err_data)
# Process saved stdout into file(s) that are included in the TeX document.
#
Anyways, open(..., encoding=encoding) is meaningless, because the file-like object is then passed to subprocess.Popen which is only interested in .fileno() of this file-like object.
Maybe you've seen software which doesn't know how to output to stdout and can only output to files. Sometimes you can pass /dev/stdout and this even works. I would like to do this the middle of python code. But, this piece of software opens /dev/stdout in w mode and since /dev/stdout points to ###.out regular file, the file gets truncated and there is no longer =>PYTHONTEX:STDOUT#{0}#code# in the beginning, which confuses PythonTeX.
The second reason is simply that open(..., encoding=encoding) doesn't do what you expect it to do.
Activity
gpoore commentedon Dec 14, 2019
Please clarify how this would be an improvement for you compared to the current system. What prompted this issue?
anerokhi commentedon Dec 14, 2019
Maybe you've seen software which doesn't know how to output to stdout and can only output to files. Sometimes you can pass
/dev/stdoutand this even works. I would like to do this the middle of python code. But, this piece of software opens/dev/stdoutinwmode and since/dev/stdoutpoints to###.outregular file, the file gets truncated and there is no longer=>PYTHONTEX:STDOUT#{0}#code#in the beginning, which confuses PythonTeX.The second reason is simply that
open(..., encoding=encoding)doesn't do what you expect it to do.