Передача значения из скомпилированного C++ в TypeScriptC++

Программы на C++. Форум разработчиков
Anonymous
Передача значения из скомпилированного C++ в TypeScript

Сообщение Anonymous »

Мне нужно передать данные, которые распечатывает скомпилированный файл C++, в проект TypeScript, который сохранит переданные данные в переменной.
Файл 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}`);
});
Я включил путь к файлу CPP в tsconfig.json:

Код: Выделить всё

[
"compilerOptions": {...},
"include":
[
"src/**/*",
"../../folder/*"
]
]

Тем не менее, выходные данные отладки всегда сообщают, что CPP-файла нет, даже если он отлично печатает путь к CPP-файлу.
Что я делаю неправильно или что мне не хватает?
>

Подробнее здесь: https://stackoverflow.com/questions/786 ... typescript

Вернуться в «C++»