Hello everyone,
I am trying to use --always-assist
functionality in a node.js application, my goal is create a interactive season within node.js and show questions to user and get inputs from them and send back to the dfx as an answer.
But test code fails, command even works with dfx, not worked in same way with spawn
process
Can someone help me to understand problem, the line that started with Installling code...
catching as stderr, but why?
I am testing dfx canister install <CANISTER_NAME> --always-assist
Here is my test code
import { spawn } from 'child_process';
import readline from 'readline';
const canisterName = 'topup_frontend'; // Replace with your actual canister name
const dfxProcess = spawn('dfx', ['canister', 'install', canisterName, '--always-assist'], {
stdio: ['pipe', 'pipe', 'pipe']
});
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// Handle stdout
dfxProcess.stdout.on('data', (data) => {
const output = data.toString();
console.log('Stdout:', output);
// Check if the output is asking for input
if (output.includes('?')) {
rl.question('Input required: ', (answer) => {
dfxProcess.stdin.write(answer + '\n');
});
}
});
// Handle stderr
dfxProcess.stderr.on('data', (data) => {
console.error('Stderr:', data.toString());
});
// Handle process exit
dfxProcess.on('close', (code) => {
console.log(`Child process exited with code ${code}`);
rl.close();
});
rl.on('close', () => {
console.log("Interactive session ended");
process.exit(0);
});
Output of Test Code
Output of dfx
Install Command Details: sdk/src/dfx/src/commands/canister/install.rs at master · dfinity/sdk · GitHub