while
cd ./tools/darwin/ && ./adb
works in my mac terminal,
my node.js application with this piece of code
const CHANGE_DIRECTORY_COMMAND = "cd ./tools/darwin/"
const EXECUTE_ADB_COMMAND = "./adb"
if(platform === "darwin") {
exec(`${CHANGE_DIRECTORY_COMMAND} && ${EXECUTE_ADB_COMMAND}`, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing the adb file: ${error}`);
return;
}
if (stdout) {
console.log(`Standard output: ${stdout}`);
}
if (stderr) {
console.error(`Standard error: ${stderr}`);
}
});
}
gives this error,
Error executing the adb file: Error: Command failed: cd ./tools/darwin/ && ./adb
in addition, this code works pretty well,
const { exec } = require("child_process");
let commandOne = "ls -l"; // display all files in current directory with (-l) long format
let commandTwo = "whoami"; // print the current user
let commandThree = "pwd"; //print the name of current directory
exec(`${commandOne} && ${commandTwo} && ${commandThree}`, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`Output: ${stdout}`);
});