I am using NodeJs to run JXA (JavaScript for Automation). Below is my code:
const spawn = require("child_process").spawn;
const StringToStream = require('string-to-stream');
const code = `
ObjC.import('stdlib');
console.log('inited');
`;
const child = spawn(
"osascript",
["-il", "JavaScript"],
{
maxBuffer: 1024 * 1024 * 1024
}
);
child.stdout.on('data', (data) => {
// Very strange, it didn't run to here
});
child.stderr.on('data', (data) => {
console.log(data.toString());
// run to hear. but the data be cut off
});
StringToStream(`
console.log('... Very-Long-String ...');
`).pipe(child.stdin, { end: false })
Very strange, stderr.on('data')
be fired, and data
be cut off. It seems that the output stream is length limited.
Does anyone know how to solve this problem ?