csharp-process/example.js
2021-02-10 22:41:24 +08:00

50 lines
1.5 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { setInterval } = require('timers');
const Process = require('./csharp-process');
//正常启动一个exe
// var exeservice=new childprocess('./exe/NodeSharpTest.exe');
// console.log(exeservice);
//高级启动
// var defaultOpt = {
// exe: 'NYSProcess.exe',//exe 路径
// closeCallback: function (exitcode) { },//exe退出的回调
// autoReOpen: false,//是否自动启动如exe异常终止后可以自动重启
// args: []//给exe的启动参数
// };
const processOption = {
exe: '',
autoReOpen: true,
args: []
};
const service = new Process('./exe/NodeSharpTest.exe', (result, error) => {
// console.log('result:',result,error)
});
//exe已经运行时的 通信对象要求是必须可以格式化为json字符串而且必须有command字段
var onceParam = { command: 'once', data: "demo" };
// 一次性的回调,执行后即被回收
var onceFunction = function (err, data) { console.log(data); };
/***
var alwaysparam = { command: 'always', data: { demo: "this is demo date" } };
// 监听性的回调创建后可伴随exe整个生命周期
var alwaysfun = function (err, data) {
if (err) {return console.error(err);}console.log(data);
};
*/
// service.send(onceParam, onceFunction);
// exeservice.send(alwaysparam, function () { }, alwaysfun);
(async () => {
try {
const result = await service.send({ title: '测试标题', message: "内容xxx", number: '123123' }, 'print');
console.log('C# return result:', result)
} catch (e) {
console.log('C# return ', e)
}
service.exit();
})();