Файл C++ не сложен и возвращает такие данные: p>
Код: Выделить всё
#include
using namespace std;
int main();
{
string dataToPass = "here's some data I want to pass";
cout {
const childExec = spawn(childExecPath);
let output = '';
childExec.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
output += data.toString();
});
childExec.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
childExec.on('close', (code) => {
console.log(`child process exited with code ${code}`);
if (code !== 0) {
reject(new Error(`Process exited with code ${code}`));
} else {
resolve(output);
}
});
childExec.on('error', (err) => {
console.error(`Failed to start process: ${err}`);
reject(err);
});
});
}
Код: Выделить всё
import { exec } from 'child_process';
import * as path from 'path';
// Use absolute path
const childExecPath = path.resolve(__dirname, '../../folder/CPPfile');
console.log(`Running: ${dataPasserPath}`);
exec(childExecPath, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
if (stderr) {
console.error(`Stderr: ${stderr}`);
return;
}
const data = stdout;
console.log(`Sensitive Data from C++: ${data}`);
});
Код: Выделить всё
[
"compilerOptions": {...},
"include":
[
"src/**/*",
"../../folder/*"
]
]
Что я делаю неправильно или что мне не хватает?
>
Подробнее здесь: https://stackoverflow.com/questions/786 ... typescript