Comments (18)
Does adding '-i'
to the arguments in the last lines do anything?
Looks like we've forgot to include -i
in sp.sync
😟
from shell-path.
@silverwind nope, but sudo -Hiu max env
can access my PATH:
from shell-path.
sudo -Hiu max env
Interesting. Is that the minimum amount of arguments needed for it to work? Not sure we can or should use sudo
just to get PATH
.
from shell-path.
Im not sure familiar with that command, but it doesn't actually require sudo permissions to run
from shell-path.
from man sudo
:
-H The -H (HOME) option sets the HOME environment variable to the homedir of the target user (root by default) as specified in passwd(5). The
default handling of the HOME environment variable depends on sudoers(5) settings. By default, sudo will set HOME if env_reset or
always_set_home are set, or if set_home is set and the -s option is specified on the command line.
-i [command]
The -i (simulate initial login) option runs the shell specified in the passwd(5) entry of the target user as a login shell. This means that
login-specific resource files such as .profile or .login will be read by the shell. If a command is specified, it is passed to the shell for
execution. Otherwise, an interactive shell is executed. sudo attempts to change to that user's home directory before running the shell. It
also initializes the environment, leaving DISPLAY and TERM unchanged, setting HOME, MAIL, SHELL, USER, LOGNAME, and PATH, as well as the
contents of /etc/environment on Linux and AIX systems. All other environment variables are removed.
-u user The -u (user) option causes sudo to run the specified command as a user other than root. To specify a uid instead of a user name, use #uid.
When running commands as a uid, many shells require that the '#' be escaped with a backslash ('\'). Note that if the targetpw Defaults option
is set (see sudoers(5)) it is not possible to run commands with a uid not listed in the password database.
from shell-path.
If it doesn't require actual elevation, that's fine. I didn't even know sudo
had such functionality. Some of that might be OS X specific. Thanks for finding this!
from shell-path.
oh yea echo $PATH
works too. you'd just need to run whoami
first to get the username to use (or use some other method)
from shell-path.
Awesome! This looks to works well on OS X:
child_process.execFileSync('sudo', ['-Hiu', process.env.USER, 'echo $PATH']).toString()
Looks like sudo
on Linux supports these flags too, thought my shell seems to have some issues, probably needs some escaping (I use zsh on both Linux and OS X):
> child_process.execFileSync('sudo', ['-Hiu', process.env.USER, 'echo $PATH']).toString()
zsh:1: no such file or directory: echo /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
Error: Command failed: sudo -Hiu silverwind echo $PATH
from shell-path.
Might as well parse it out of env
so it works on both Linux and OS X:
/PATH=(.+)\n/.exec(require('child_process').execFileSync('sudo', ['-Hiu', process.env.USER, 'env']).toString() || [])[1]
Edit: I see slightly different results using both methods on Ubuntu:
> /PATH=(.+)\n/.exec(require('child_process').execFileSync('sudo', ['-Hiu', process.env.USER, 'env']).toString() || [])[1].trim()
'/usr/local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin'
> child_process.execFileSync('/bin/sh', ['-i', '-c', 'echo $PATH']).toString().trim()
'/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/bin/X11:/usr/games'
> process.env.PATH
'/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/bin/X11:/usr/games'
I'll play in Electron to find out which method works best.
from shell-path.
Cross-referencing with sindresorhus/fix-path#4
Looks to be the same issue.
from shell-path.
I'm seeing this as well. I'm using zsh but it's in process.env.SHELL so I don't think that should be the issue. Attached is some debugging.
from shell-path.
@maaarghk your issue with the sync method is fixed by 2e8c3f3, I'll push a release with that.
from shell-path.
I was literally just about to come here and say that I noticed that missing flag :) Thanks!
from shell-path.
Looks @sindresorhus has to publish 1.0.3, Seems like I'm missing npm access on this repo.
from shell-path.
@silverwind Published, and you do now.
from shell-path.
👍
from shell-path.
Updated master to use both methods of obtaining the path and returning the longest path found out of all methods. Had a weird issue with execFileSync
on Linux where
child_process.execFileSync('sudo', ['-Hiu', process.env.USER, 'echo $PATH'], {encoding: 'utf8'})
did fail with a zsh:1: no such file or directory
. Switching to
child_process.execSync('sudo -Hiu' + process.env.USER + ' echo $PATH', {encoding: 'utf8'})
remedied that. May be a node bug.
from shell-path.
Released 1.0.4 with this.
from shell-path.
Related Issues (13)
- just return the %PATH% on windows HOT 3
- Node 0.10 support for `.sync` method HOT 2
- Force interactive shell for common shells HOT 8
- sync method doesn't work in Electron Renderer HOT 1
- /usr/local/bin not included in returned path HOT 9
- latest techniques still not working in electron sadly HOT 4
- Problem when shell startup prints a string HOT 4
- Remove `sudo` check HOT 4
- TypeError: Cannot read property 'length' of null HOT 28
- Not working HOT 18
- Getting error on module.exports = () => shellEnv().then(x => x.PATH) HOT 1
- SyntaxError: Cannot use import statement outside a module HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shell-path.