Node-Webkit子流程执行器 [英] Node-Webkit Child Process Exec

查看:74
本文介绍了Node-Webkit子流程执行器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行一个自制程序命令

I want to execute a homebrew command for example

brew list

我遵循了文档并按如下方式执行它:

I followed the documentation and executed it like this:

child = exec('brew', function (error, stdout, stderr) {
 console.log(stdout);
 console.log(stderr);
});

我收到一条命令未找到错误,并意识到如果我将/usr/local/bin/brew作为命令执行,它将起作用.但是,简单地使用"brew"也应该可以工作,因为我可以像这样从命令行运行"brew".

I am getting a command not found error, and realized that if I do /usr/local/bin/brew as the command it works. However simply using 'brew' should work as well since I can run 'brew' from the command line just as such.

为什么会这样?如何使"brew"作为子进程在节点中运行?我有一个问题的感觉,因为node-webkit上的命令似乎是从bin/sh执行的.

Why is this the case and what does it take to make 'brew' run as a child process in node? I have a feeling part of the issue because the command on node-webkit seems to execute from bin/sh.

谢谢

推荐答案

这可能取决于您如何启动node-webkit以及如何设置PATH.当我从命令行启动时,它将从我的命令行环境(包括PATH)继承环境变量.如果我首先双击gui,它将从系统继承(大概是/etc/paths),并且我在.bashrc/.bash_profile中添加的任何内容均无效.

It may depend on how you're starting node-webkit and how you're setting your PATH. When I start from the command line, it inherits the environment variables from my command-line environment, including PATH. If I start by double clicking in a gui, it inherits from the system (presumably /etc/paths), and any additions I make in my .bashrc/.bash_profile have no effect.

我也不是安全专家,但是我对最佳实践的理解将包括使用您正在运行的可执行文件的绝对路径,因此更难通过设置环境变量来进行欺骗.通过这种方式,最好还是使用完整的brew路径.

Also, I'm no security expert, but my understanding of best practices would include using an absolute path to the executable you're running, so it's harder to spoof by setting an environment variable. By that measure, you're better off using the full path to brew anyway.

这篇关于Node-Webkit子流程执行器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆