<commit_before>diff --git a/cram.py b/cram.py
index 20c4681..3b9f144 100755
--- a/cram.py
+++ b/cram.py
@@ -168,14 +168,14 @@ def test(path, shell, indent=2):
     cmdline = '%s$ ' % indent
     conline = '%s> ' % indent
 
-    f = open(path)
+    f = open(path, 'r', encoding='utf-8')
     abspath = os.path.abspath(path)
     env = os.environ.copy()
     env['TESTDIR'] = os.path.dirname(abspath)
     env['TESTFILE'] = os.path.basename(abspath)
     p = subprocess.Popen([shell, '-'], bufsize=-1, stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
-                         universal_newlines=True, env=env,
+                         universal_newlines=False, env=env,
                          preexec_fn=makeresetsigpipe(),
                          close_fds=os.name == 'posix')
     salt = 'CRAM%s' % time.time()
@@ -199,7 +199,9 @@ def test(path, shell, indent=2):
             after.setdefault(pos, []).append(line)
     stdin.append('echo "\n%s %s $?"\n' % (salt, i + 1))
 
-    output = p.communicate(input=''.join(stdin))[0]
+    print(f.encoding) 
+    print(sys.stdout.encoding) 
+    output = p.communicate(input=''.join(stdin).encode('utf-8'))[0].decode('utf-8')
     if p.returncode == 80:
         return (refout, None, [])
 
@@ -336,7 +338,7 @@ def run(paths, tmpdir, shell, quiet=False, verbose=False, patchcmd=None,
                 log('!', 'failed\n', verbose)
                 if not quiet:
                     log('\n', None, verbose)
-                errfile = open(errpath, 'w')
+                errfile = open(errpath, 'w', encoding='utf-8')
                 try:
                     for line in postout:
                         errfile.write(line)<commit_msg>Removed debug logging on cram patch<commit_after>diff --git a/cram.py b/cram.py
index 20c4681..3b9f144 100755
--- a/cram.py
+++ b/cram.py
@@ -168,14 +168,14 @@ def test(path, shell, indent=2):
     cmdline = '%s$ ' % indent
     conline = '%s> ' % indent
 
-    f = open(path)
+    f = open(path, 'r', encoding='utf-8')
     abspath = os.path.abspath(path)
     env = os.environ.copy()
     env['TESTDIR'] = os.path.dirname(abspath)
     env['TESTFILE'] = os.path.basename(abspath)
     p = subprocess.Popen([shell, '-'], bufsize=-1, stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
-                         universal_newlines=True, env=env,
+                         universal_newlines=False, env=env,
                          preexec_fn=makeresetsigpipe(),
                          close_fds=os.name == 'posix')
     salt = 'CRAM%s' % time.time()
@@ -199,7 +199,7 @@ def test(path, shell, indent=2):
             after.setdefault(pos, []).append(line)
     stdin.append('echo "\n%s %s $?"\n' % (salt, i + 1))
 
-    output = p.communicate(input=''.join(stdin))[0]
+    output = p.communicate(input=''.join(stdin).encode('utf-8'))[0].decode('utf-8')
     if p.returncode == 80:
         return (refout, None, [])
 
@@ -336,7 +336,7 @@ def run(paths, tmpdir, shell, quiet=False, verbose=False, patchcmd=None,
                 log('!', 'failed\n', verbose)
                 if not quiet:
                     log('\n', None, verbose)
-                errfile = open(errpath, 'w')
+                errfile = open(errpath, 'w', encoding='utf-8')
                 try:
                     for line in postout:
                         errfile.write(line)
{'fraction_non_alphanumeric': 0.1716526285216381, 'fraction_numerical': 0.03194888178913738, 'mean_word_length': 1.9766637856525497, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1961634', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1174, 'n_words': 220}