美文网首页
pyexecjs 异常记录

pyexecjs 异常记录

作者: SodaCrush | 来源:发表于2024-03-11 17:22 被阅读0次

    issues

    1. encoding error
    import subprocess
    from functools import partial
    subprocess.Popen = partial(subprocess.Popen, encoding="utf-8")
    
    1. module not found:
      解决办法:指定node_modules所在目录
    js = execjs.compile(
      open(path.join(BASE_PATH, "tools/xxx.js"), "r", encoding="utf-8").read(),
      cwd=path.join(BASE_PATH, "tools/node_modules")
    )
    
    1. 获取Promise结果
    abs_path = path.join(BASE_PATH, "js/manifest.js")
    process = subprocess.Popen(["node", abs_path, data], stdout=subprocess.PIPE)
    output, error = process.communicate()
    clean_res = output.decode('utf-8').strip()
    print(clean_res)
    

    相关文章

      网友评论

          本文标题:pyexecjs 异常记录

          本文链接:https://www.haomeiwen.com/subject/krwmzdtx.html