js_exec
result =python_exec(code, [vars=])/js_exec(code, [vars=])
Input: code, vars · Output: result
What it is
Runs code (string, source in the guest language) as a subprocess. vars (optional, a Record) is injected into the guest as ordinary variables. The guest writes its result as JSON to an injected output-path variable (_qu_output_path), which this call reads back.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = python_exec(code, [vars=]) / js_exec(code, [vars=]) | code stringRuns code (string, source in the guest language) as a subprocess.vars Record, optionalvars (optional, a Record) is injected into the guest as ordinary variables. | result — | Returns a record {stdout, stderr, success, exit_code, result}: captured output streams, whether the process exited cleanly, its exit code, and the parsed JSON result. For a library with no Qu equivalent yet — and a dependency to be honest about in anything published using it. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
py = python_exec("result = 1 + 1\nimport json\njson.dump(result, open(_qu_output_path, 'w'))")
print(py.result) # 2
py2 = python_exec("import json\nresult = x * 2\njson.dump(result, open(_qu_output_path, 'w'))", vars={x=21})
print(py2.result) # 42
js = js_exec("const fs = require('fs'); fs.writeFileSync(_qu_output_path, JSON.stringify(1 + 1));")
print(js.result) # 2
output
2 42 2
from file-io
How it works
Other inline languages share one implementation -- see deliberately excludes.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.
See also
python_exec — documented in the same entry.