Execute `js` using given `node` executable.
(node: str, js: str)
| 142 | # exec 改为同步----------------------------- |
| 143 | @staticmethod |
| 144 | def exec(node: str, js: str) -> str: |
| 145 | """Execute `js` using given `node` executable.""" |
| 146 | p = subprocess.Popen( |
| 147 | node, |
| 148 | stdin=subprocess.PIPE, |
| 149 | stdout=subprocess.PIPE, |
| 150 | stderr=subprocess.PIPE, |
| 151 | executable=which(node), |
| 152 | ) |
| 153 | stdout, stderr = p.communicate(js.encode()) |
| 154 | removesuffix = lambda s: s[:-1] if str.endswith(s, "\n") else s |
| 155 | if stderr: |
| 156 | raise JsRuntimeError(p.returncode or 1, node, removesuffix(stderr.decode())) |
| 157 | return removesuffix(stdout.decode()) |
| 158 | |
| 159 | def bind(self, expr: Optional[JsExpr] = None): |
| 160 | """Return an partial of `.exec`, with `node` set to :obj:`.node`, |
no test coverage detected