MCPcopy Create free account
hub / github.com/Sandpack/nodebox-runtime / foo

Function foo

tests/examples/exec.example.js:10–39  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8 */
9window.runExample = async function (emulatorUrl) {
10 const foo = async () => {
11 const { Nodebox } = window;
12
13 const emulator = new Nodebox({
14 runtimeUrl: emulatorUrl,
15 iframe: document.getElementById('frame'),
16 });
17
18 await emulator.connect();
19 await emulator.fs.init({
20 'foo.js': `process.stdout.write('Hello world');
21process.exit();`,
22
23 'index.js': `const { exec } = require('node:child_process');
24
25exec("./foo", { encoding: "utf8", timeout: 5_000 }, (err, stdout, stderr) => {
26 console.log("Exec output: " + stdout)
27});`,
28 });
29
30 const shellProcess = emulator.shell.create();
31
32 return new Promise(async (resolve) => {
33 shellProcess.stdout.on('data', (data) => {
34 return resolve(data);
35 });
36
37 await shellProcess.runCommand('node', ['index.js']);
38 });
39 };
40
41 console.log(await foo());
42};

Callers 1

exec.example.jsFile · 0.70

Calls 5

connectMethod · 0.95
initMethod · 0.80
createMethod · 0.80
runCommandMethod · 0.80
onMethod · 0.45

Tested by

no test coverage detected