How to run a complex command in node js spawn?

I am developing lib for the docker command line in nodejs, I am still at the beginning, I just tried running the docker command with spawn in node js - everything works fine, but it doesn’t work for complex cases like the one below.

I want to run docker run --rm -it julia:0.3.6 julia -E "[x^2 for x in 1:100]"in nodejs, but I get below errors -

input device is not TTY

Docker Shell existed with status = 1

Below code is

    const
        spawn = require('child_process').spawn,
        dockerDeamon = spawn("docker", ["run","--rm", "-it", "julia:0.3.6", "-E",   "\" [x^2 for x in 1:100]\""] );

    dockerDeamon.stdout.on('data', data => {
        console.log(`${data}`);

    });

    dockerDeamon.stderr.on('data', data => {
        console.log(`${data}`);

    });

    dockerDeamon.on('close', code => {
        console.log(`Docker Shell existed with status = ${code}`);

    });

Is there a better way to execute the script described above?

+3
source share
1 answer

-t (--tty) Docker, , , (TTY). , spawn, Node.js . Input device is not a TTY. -t.


, , "\" [x^2 for x in 1:100]\"". , , spawn, .

, :

dockerDeamon = spawn("docker", ["run","--rm", "-i", "julia:0.3.6", "julia", "-E", "[x^2 for x in 1:100]"] );
+5

Source: https://habr.com/ru/post/1683207/


All Articles