如何使用node.js添加临时环境路径

时间:2018-05-29 07:09:59

标签: node.js flutter

我尝试的是:

  exec( "export PATH=/Users/shubhamkumar/flutter/bin:$PATH",
 (err, stdout, stderr) => {
      if (err) {
        console.log(err); // node couldn't execute the command
        return;
      }
      // the *entire* stdout and stderr (buffered)
      console.log(`stdout: ${stdout}`);
      console.log(`stderr: ${stderr}`);
    });

但它没有将路径设置为临时路径。 当我试图执行此

 exec("flutter doctor", (err, stdout, stderr) => {
      if (err) {
        console.log(err); // node couldn't execute the command
        return;
      }
      // the *entire* stdout and stderr (buffered)
      console.log(`stdout: ${stdout}`);
      console.log(`stderr: ${stderr}`);
    });

它说'命令未找到:颤动'

1 个答案:

答案 0 :(得分:0)

您可以通过设置process.env对象临时设置env变量。尝试以下(未经测试):

process.env.PATH = '/Users/shubhamkumar/flutter/bin:' + process.env.PATH

exec("flutter doctor", (err, stdout, stderr) => {
      if (err) {
        console.log(err); // node couldn't execute the command
        return;
      }
      // the *entire* stdout and stderr (buffered)
      console.log(`stdout: ${stdout}`);
      console.log(`stderr: ${stderr}`);
    });