Skip to content

Commit

Permalink
fix: process spawning in cli/utils (#1237)
Browse files Browse the repository at this point in the history
* fix process spawning in cli/utils

* fix test-ledger path
  • Loading branch information
sergeytimoshin authored Sep 19, 2024
1 parent 94823b4 commit 46b89e0
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions cli/src/utils/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,35 @@ export function spawnBinary(command: string, args: string[] = []) {
const logDir = "test-ledger";
const binaryName = path.basename(command);

const dir = path.join(__dirname, logDir);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
const dir = path.join(__dirname, "../..", logDir);
try {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}

const out = fs.openSync(`${logDir}/${binaryName}.log`, "a");
const err = fs.openSync(`${logDir}/${binaryName}.log`, "a");
const spawnedProcess = spawn(command, args, {
stdio: ["ignore", out, err],
shell: false,
detached: true,
});
const logPath = path.join(dir, `${binaryName}.log`);
const out = fs.openSync(logPath, "a");
const err = fs.openSync(logPath, "a");

spawnedProcess.on("close", (code) => {
console.log(`${binaryName} process exited with code ${code}`);
});
const spawnedProcess = spawn(command, args, {
stdio: ["ignore", out, err],
shell: false,
detached: true,
});

spawnedProcess.on("close", (code) => {
console.log(`${binaryName} process exited with code ${code}`);
});

return spawnedProcess;
} catch (error: unknown) {
if (error instanceof Error) {
console.error(`Error spawning binary: ${error.message}`);
} else {
console.error(`An unknown error occurred while spawning binary`);
}
throw error;
}
}

export async function waitForServers(
Expand Down

0 comments on commit 46b89e0

Please sign in to comment.