I'm working on a node script that will do some stuff with execa
package.
Basically I want that script to change directory to certain path and then run another mand within that path.
I did it like that:
execamand('cd /some/dir && pwd');
But pwd
mand won't execute for some reason, though it finishes successfully.
What could be the reason, the mand after &&
won't execute, and is there any other way to manage that task?
Thanks!
I'm working on a node script that will do some stuff with execa
package.
Basically I want that script to change directory to certain path and then run another mand within that path.
I did it like that:
execa.mand('cd /some/dir && pwd');
But pwd
mand won't execute for some reason, though it finishes successfully.
What could be the reason, the mand after &&
won't execute, and is there any other way to manage that task?
Thanks!
Share Improve this question asked Feb 11, 2020 at 17:59 abstractmindabstractmind 10710 bronze badges 1-
2
docs say: "The shell option must be used if the mand uses shell-specific features, as opposed to being a simple file followed by its arguments." I'm guessing
&&
might be considered a shell-specific feature? – David784 Commented Feb 11, 2020 at 18:05
1 Answer
Reset to default 8The question you should be asking is "How do I run a mand with a different working directory?", which will give you the simple, robust, cross-platform solution of using the cwd
option:
execa.mand('pwd', { cwd: '/some/dir' });
If you instead want to acplish this task with &&
, you can do that by invoking a shell. This is more fragile and platform specific:
execa('sh', ['-c', 'cd /some/dir && pwd']);