first commit
This commit is contained in:
33
test.js
Normal file
33
test.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const { execSync } = require('child_process');
|
||||
const path = require('path');
|
||||
|
||||
/**
|
||||
* 同步方式调用控制台程序并判断授权
|
||||
* @param {string} command - 要执行的命令
|
||||
* @returns {object} - 授权结果
|
||||
*/
|
||||
function checkAuthorizationSync(command) {
|
||||
try {
|
||||
const output = execSync(command, {
|
||||
encoding: 'utf-8',
|
||||
timeout: 10000 // 10秒超时
|
||||
});
|
||||
|
||||
console.log('授权查询结果:', JSON.parse(output));
|
||||
return JSON.parse(output);
|
||||
|
||||
} catch (error) {
|
||||
console.error('执行失败:', error);
|
||||
return { error: error.message, authorized: false };
|
||||
}
|
||||
}
|
||||
|
||||
// 使用示例
|
||||
if (require.main === module) {
|
||||
const exeDir = path.join(process.cwd(), 'exe');
|
||||
const syncResult = checkAuthorizationSync(`.\\exe\\Test.exe 10303 ${exeDir}`);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
checkAuthorizationSync,
|
||||
};
|
||||
Reference in New Issue
Block a user