在 golang 项目/文件中执行节点脚本
我正在尝试在我的 golang 项目中执行或运行节点脚本。我正在使用 os/exec
data, err := exec.Command("node api.js", "resources/node/api.js").Output()
if err != nil {
panic(err)
}
output := string(data)
fmt.Println(output)
这是我得到的响应:
panic: exec: "node api.js":executable file not found in %PATH%
不确定我可能错了什么,或者是否有其他方法来执行此命令。我发现的只是执行 .sh 命令的方法,
我们将非常感谢您的帮助。
I'm trying to exec or run a node script inside my golang project. I'm using os/exec
data, err := exec.Command("node api.js", "resources/node/api.js").Output()
if err != nil {
panic(err)
}
output := string(data)
fmt.Println(output)
this it the response I'm getting:
panic: exec: "node api.js": executable file not found in %PATH%
Not sure What I might be wrong or if there is an alternative way to execute this command. All I found was ways to execute .sh command
Your assistance will be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过使用命令和文件的绝对路径解决了这个问题,这里是一个工作代码示例:
I resolved it by using absolute paths for both the command and the file, here is a working code sample: