【问题标题】:Not able to open terminal in MacOS while running .sh files with child_process使用 child_process 运行 .sh 文件时无法在 MacOS 中打开终端
【发布时间】:2020-01-14 10:31:34
【问题描述】:

以下代码 sn-p 打开 Git bash 并在 Windows 中运行 shell 命令。但在 MacOS 中,它不会打开终端。没有运行 Shell 脚本。

const exec = require('child_process').exec;
var str = "test.sh"
const myShellScript = exec(str);

myShellScript.stdout.on('data', (data)=>{
        console.log(data); 
    });
myShellScript.stderr.on('data', (data)=>{
        console.error(data);
    });

【问题讨论】:

  • 这是一个 js 文件,当我在 windows 上使用 nodejs 运行此文件时,它会打开 gitbash 并正确运行 shell 脚本,但是当我尝试在 MacOS 上执行相同操作时,它不会打开终点站。请帮忙
  • shell 如何知道您的脚本位于哪个目录?它的 PATH 是否包含当前目录 (.) ?
  • 是的。我没有指定路径,因为脚本和 shell 文件都在同一个目录中。

标签: node.js reactjs shell child-process


【解决方案1】:

这是一个愚蠢的错误。要执行,语法是“sh filename.sh”。问题解决了。 点击(https://medium.com/stackfame/how-to-run-shell-script-file-or-command-using-nodejs-b9f2455cb6b7)了解更多

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-11
    • 2017-03-12
    • 2014-06-17
    • 1970-01-01
    • 2013-04-18
    相关资源
    最近更新 更多