Skip to content

Pls consider using subprocess.PIPE instead of out_file and err_file #161

Description

@anerokhi

Something like

--- /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.

Thanks.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions