-
Notifications
You must be signed in to change notification settings - Fork 738
exec doesn't work in electron #480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@jeremyrajan: Can you expand the error messages to see the full stacks? Thanks! |
Hi @ariporad , apologies for delay. Following is the full stack trace: exec('node --version', {silent:true})
/Users/jr/Documents/Projects/Github/installer_app/node_modules/shelljs/src/com…:40
exec: internal errorlog @ /Users/jr/Documents/Projects/Github/installer_app/node_modules/shelljs/src/com…:40
error @ /Users/jr/Documents/Projects/Github/installer_app/node_modules/shelljs/src/com…:68
_exec @ /Users/jr/Documents/Projects/Github/installer_app/node_modules/shelljs/src/exe…:256
(anonymous function) @ /Users/jr/Documents/Projects/Github/installer_app/node_modules/shelljs/src/com…:269
(anonymous function) @ VM345:1 Essentially, what I am trying to do get the version for a list of installed apps/packages. If there is a better way, that would be great as well 👍 Thank you :) |
Any idea guys? :). Neither of the exec commands are working for me |
The only workaround I know might be |
Hmm... We do seem to have a lot of problems with electron, don't we? @jeremyrajan: Will you try this with the |
@ariporad Do you need any further information? Mac OS X 10.11.6 e.message
e.stack
|
Ohh... I think I know the problem: I think Electron is breaking |
@giacgbj: So, it would appear that the node binary is built in to the electron executable, and as such we can't run it individually. This is problematic, and I'm really not sure how we can work around it. |
@ariporad Suggestion: var nodePath = isValid(process.execPath) ? process.execPath
: (which('node') || which('nodejs'));
if (!nodePath)
throw new Error('Unable to find path to NodeJS executable'); Check the semantics of |
@nfischer: I'm not really sure what mv /usr/bin/node /usr/bin/myNodeJSWithAFunnyName
myNodeJSWithAFunnyName script.js |
Yes, that's the rationale behind using Just test if |
@nfischer: There would be no way to test if it's part of electron. For example, Slack is written with Electron. From Slack's perspective, I don't think we could just test if the path ends in We could have a Another thing is that Electron apps are frequently non-developer facing, so it might be bad to require people to have a seperate node instance on their machines. |
@ariporad perhaps electron/electron#2288 would help us? That'll tell us if we're running in electron. If so, we know that |
Is there a reason you can't simply call exec/execSync from node's child_process? |
Hmm... @giacgbj, Good point. @jeremyrajan? |
hmm, that works too but is it cross platform compatible because I believe normally we have to execute a bat file for WIN? Or am i totally wrong :) |
var ret = child_process.execSync('node --version'); What's the issue with Windows? |
Closing this because we've documented a workaround on the wiki. Please comment if this workaround is insufficient. |
As per wiki I need to set 'config.execPath', How can I specify that? Any sample example for it? |
@HardikDG please see the wiki, it explains how you might find the path to your node binary... |
@nfischer I already saw the wiki, from the wiki itself I come to this post, I got the path to the node in my system. Sorry if it's very stupid question but I don't have deep knowledge of NodeJS, so I don't have that idea. |
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... |
@nfischer Thanks. It worked in my electron app. |
@nfischer Hi, glad to see there is a workaround. Tried this in an electron app and got failed after throwing an error
May I know is there a compatible library version to make this work? Thank you |
@gayanai does that workaround not work for you? This is still hit-or-miss, and we don't guarantee that workaround (otherwise, we would bake it into shelljs core). |
@nfischer Hi , the workaround not works um using the latest macos environment with the latest electron framework. Thanks |
@gayanai well, where is your path to $ which node || which nodejs # does this point to something? Whatever that points to should be your |
@nfischer Hi |
@gayanai if that doesn't fix the issue, then you'll need to provide full error output |
setting exec to async seems to work.
|
@hazim-j yes, that is another valid workaround (assuming async works for your use-case). Now that we have async/await in some versions of node, maybe this is a better workaround. |
@nanjixiong218 thanks for reporting. Yes, it seems this isn't quite working. I'm not sure what that file ( |
|
Forgive my ignorance... If you're bundling the app, couldn't you create an npm dependency to node@compatible-version and reference that? |
If you're requesting that ShellJS bundle |
Thanks to hazim-j above, I got shelljs working within electron like this:
|
Node version:
6.2.0
ShellJS version
0.7.0
Operating system:
Mac
Description of the bug:
I am trying to run the following command (that I copied from docs) in my electron console.
Any idea, why this would be having. As I want to return the version number for checks. Other commands such as
which
are working but justexec
Thank you! :)
The text was updated successfully, but these errors were encountered: