2

I am trying to execute two windows commands in sequence and get the result of the later one. Something like:

cd ${directory}
sfdx force:source:convert -d outputTmp/ --json

I have browsed and tried a bunch of third-party libraries, like node-cmd. But so far I haven't got any luck yet. As in node-cmd example:

cmd.get(
    `cd ${directory}
    sfdx force:source:convert -d outputTmp/ --json`,
    function(err, data, stderr) {

This works very well on my macOS machine. But on Windows it tends to execute only the first command.

Is there anyway I can resolve this issue? Even some walk around for just cd {directory} + real command can be really helpful

2
  • DId you installed all the packages required for the second command on your widows machine (cf: sfdx) ? Does the stderr in the callback return anything ? Commented Mar 7, 2018 at 23:52
  • @NathanSchwarz sfdx runs without any issue. In the callback function, the error is null and the data is empty. And if I execute the sfdx command directly, it has no issue. Commented Mar 7, 2018 at 23:54

1 Answer 1

2

You can try this:

const exec = require('child_process').exec;

exec(`cd dir 
      sfdx force:source:convert -d outputTmp/ --json`, (err, stdout, stderr) => {
  if (err) {
    // node couldn't execute the command
    return;
  }
  console.log(stdout);
});

or by using && without backticks:

const exec = require('child_process').exec;

exec('cd dir && sfdx force:source:convert -d outputTmp/ --json', (err, stdout, stderr) => {
  if (err) {
    // node couldn't execute the command
    return;
  }
  console.log(stdout);
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for that. Actually a simple && can resolve my issue!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.