diff --git a/bin/hicstuff_build_matrix.py b/bin/hicstuff_build_matrix.py
index cf3fea288b882f13a0166c5b9d44b5e4a3b94214..c8bf3e49fd48a490ccd7221881bffef480dee318 100755
--- a/bin/hicstuff_build_matrix.py
+++ b/bin/hicstuff_build_matrix.py
@@ -73,7 +73,7 @@ def pairs2matrix(
 
     cmd = 'grep -v ^# %s | sort -S 2G -k8,8n -k9,9n --parallel=1' % pairs_file
     with open(pre_mat_file, "a") as fout:
-        fout.write(os.system(cmd))
+        fout.write(str(os.system(cmd)))
 
     header_size = len(hio.get_pairs_header(pre_mat_file))
     with open(pre_mat_file, "r") as pairs, open(mat_file, "w") as mat: