-
Notifications
You must be signed in to change notification settings - Fork 725
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
Shelljs exec() not executing variables #815
Comments
I think you're looking for something like: var myvar = 'devices';
var output = shell.exec('adb ' + myvar); |
Thanks @nfischer. It works !!
I will also try to work on my end on how to concat the overall command if the variable is somewhere in the middle of the command. But if you get it first please let me know. Thanks for the help again !! |
Found the Solution for the above issue: shell.exec( |
Yeah, that would throw an error. That's because there's no space before shell.exec('adb ' + myvar + ' -l'); // a space before '-l' On a related note, if you need to access environmental variables, I would recommend accessing them via shell.echo(shell.env.PATH);
shell.cp('file.txt', shell.env.HOME); // can also use '~' instead of 'shell.env.HOME'
shell.exec('chown ' + shell.env.USER + ' file.txt'); |
Node version (or tell us if you're using electron or some other framework):
v8.6.0
ShellJS version (the most recent version/Github branch you see the bug on):
"shelljs": "^0.8.0"
Operating system:
Macbook iOS high sierra 10.13.2
Description of the issue:
(New to Shelljs)
Shelljs exec command doesnot take variables. I tried all possible combinations like using double quotes, single quotes, assigning $ in front of the variable etc.
error : not found or adds all the help commands of the tool and prints out.
Need help please to understand the syntax on how to include variables inside exec function ? I might be not using the right syntax.
-Thanks
Example ShellJS command to reproduce the error:
Note filename: a.js
#!/usr/bin/env node
require('shelljs');
let output = exec('adb devices', {silent:false}).stdout;) // works perfectly fine
//Now if substitute dev in place of devices it doesn't work
let dev = "devices";
let output = exec('adb $dev', {silent:false}).stdout; //Doesn't work. errors out
//To execute the above file in the terminal, run :
node ./a.js
//note: adb is an android tool. you can use any simple command line like node --version etc
The text was updated successfully, but these errors were encountered: