[英]Node.js absolute path
I'm trying to build a Electron app which quickly pull the machine info to the user. 我正在尝试构建一个Electron应用程序,该应用程序可以快速将机器信息提供给用户。 I'm trying to use the npm module 'shelljs' to be able to use shell script in a node environment.
我正在尝试使用npm模块'shelljs'以便能够在节点环境中使用shell脚本。 But Electron doesn't really support shelljs so I'm in a bit of a pickle.
但是Electron并不真正支持shelljs,所以我有点不高兴。 There is a workaround that includes to use the absolute path to the node binary.
有一种解决方法,包括使用到节点二进制文件的绝对路径。 Not sure what they mean by that so I thought you guys could help out.
不知道这意味着什么,所以我认为你们可以帮忙。
The workaround I got is taken from here where they say this: 我得到的解决方法是从这里说的:
Set it like any regular variable.
像设置任何常规变量一样进行设置。
// This is inside your javascript file
var shell = require('shelljs');
shell.config.execPath = 'path/to/node/binary'; // Replace this with the real path
// The rest of your script...
This is my code where I get an undefined on the execPath
: 这是我在
execPath
上得到未定义的execPath
:
const shell = require('shelljs')
const path = require('path')
shell.confic.execPath = path.join('C:', 'Program Files', 'nodejs', 'node_modules', 'npm', 'bin')
Am I interpreting the workaround the wrong way? 我是否以错误的方式解释了解决方法?
The spelling error that @Chirag Ravindra pointed out did the trick. @Chirag Ravindra指出的拼写错误可以解决问题。 After a bit of thinking I came to this solution:
经过一番思考,我得出了以下解决方案:
shell.config.execPath = path.join('C:', 'Program Files', 'nodejs', 'node.exe')
//Thomas //托马斯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.