最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I execute a seria of commands with execa? - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 8

The 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']);
发布评论

评论列表(0)

  1. 暂无评论