File size: 448 Bytes
b19c92c
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
import os, subprocess

def read_text(path):
    with open(path,'r',encoding='utf-8',errors='ignore') as f: return f.read()

def write_text(path,text):
    os.makedirs(os.path.dirname(path) or '.',exist_ok=True)
    with open(path,'w',encoding='utf-8') as f: f.write(text)

def run_cmd(cmd,cwd=None):
    p=subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE,cwd=cwd)
    o,e=p.communicate();return p.returncode,o.decode(),e.decode()