Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Ability to set CWD #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ This will execute the commands `echo 1` `echo 2` and `echo 3` simultaneously.
Note that on Windows, you need to use double-quotes to avoid confusing the
argument parser.

#### Setting The Current Working Directory (CWD)

To run a command in a specified directory, pass a JSON array with the first element as the CWD and the second element as the command:

```bash
parallelshell '["/some/folder","some command"]'
```
**Note**: Due to how JSON.parse works, string input in the arrays need to be in double quotes.

Available options:
```
-h, --help output usage information
Expand Down
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,20 @@ if (process.platform === 'win32') {
// start the children
children = [];
cmds.forEach(function (cmd) {
var cwd = undefined;
try {
var cmd_tmp = JSON.parse(cmd);
if (cmd_tmp.length === 2) {
cwd = cmd_tmp[0];
cmd = cmd_tmp[1];
}
} catch(SyntaxError) {}; // Squash this error

if (process.platform != 'win32') {
cmd = "exec "+cmd;
}
var child = spawn(sh,[shFlag,cmd], {
cwd: process.cwd,
cwd: (cwd === undefined) ? process.cwd : cwd,
env: process.env,
stdio: ['pipe', process.stdout, process.stderr]
})
Expand Down