如何在节点生成中传递所有当前环境变量?

时间:2022-05-01 11:46:46

I am spawning child tasks in Node the following way:

我通过以下方式在Node中生成子任务:

function createChildProc(prog, params0, cmdAndEnv) {
    var spawn = require('child_process').spawn;
    return spawn(prog, params0, cmdAndEnv);
}

Where cmdAndEnv manually contain the environment variables created during the initial fire up of Node.

其中cmdAndEnv手动包含在Node初始启动期间创建的环境变量。

Instead of manually issuing all the environmental variables into the spawned child, is there a way to have node automatically inject the current environment variables into the child's environment?

有没有办法让节点自动将当前环境变量注入到子环境中,而不是手动将所有环境变量发布到生成的子节点中?

1 个解决方案

#1


The third argument is used to specify additional options. One of these options is env which contains the environment key-value pairs in an object.

第三个参数用于指定其他选项。其中一个选项是env,它包含对象中的环境键 - 值对。

return spawn(prog, params0, { env: cmdAndEnv });

See the documentation for more details.

有关详细信息,请参阅文档。

#1


The third argument is used to specify additional options. One of these options is env which contains the environment key-value pairs in an object.

第三个参数用于指定其他选项。其中一个选项是env,它包含对象中的环境键 - 值对。

return spawn(prog, params0, { env: cmdAndEnv });

See the documentation for more details.

有关详细信息,请参阅文档。