Coder Social home page Coder Social logo

locate-executable's Introduction

Locate Executable npm version

Locate executable files for specific commands (useful for child_process inside Electron apps)

After building an Electron app using electron-builder, the $PATH variable inside child_process may get set to /usr/bin:/bin:/usr/sbin:/sbin which makes it virtually impossible to spawn additional non-UNIX commands.

This package allows you to locate paths of executable files for such commands. You can then use these paths to spawn child_process inside the compiled app.

Install

Tested on macOS only. Let me know if it does/not work on Linux/Windows.

npm install --save locate-executable

locateExecutable(command[,subpath][,callback])

Looks for executable files for specified command in user's home directory recursively. You can narrow down the search by specifying additional subpath.

  • command (String) Command you need the executable of
  • subpath (String) (optional) Specify a particular subpath you want to look at
  • callback (Function) (optional)
    • error (String)
    • paths (Array) List of absolute paths to executables
// Example
import locateExecutable from 'locate-executable'

locateExecutable('jupyter-console', (error, paths) => {
    if (error) console.log(error)

    console.log(paths)
    return
})

NOTE: As the search inside the home directory recursively can take some time, consider running it only on the first launch and saving the paths persistently in something like electron-store.

Contribute

So if you're awesome and want to contribute to this project, go fork, clone and send pull requests! These are the tips for features to work on:

  • support for Windows and Linux (if it already doesn't work)

License

MIT

locate-executable's People

Contributors

kysely avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.