-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
46 lines (43 loc) · 1.27 KB
/
Copy pathutils.js
File metadata and controls
46 lines (43 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*******************************************************************************
*
*
* (c) Copyright Merative US L.P. and others 2020-2022
*
* SPDX-Licence-Identifier: Apache 2.0
*
*******************************************************************************/
"use strict";
var TAG = "utils.js";
var hfc = require('fabric-client');
var log4js = require('log4js');
var logger = log4js.getLogger(TAG);
var log_level = hfc.getConfigSetting('log_level') ? hfc.getConfigSetting('log_level') : "INFO";
logger.level = log_level;
const child_process = require('child_process');
module.exports.setup = function () {
};
module.exports.callExternalFunctionLocal = callExternalFunctionLocal;
function callExternalFunctionLocal(sys_user, cmd, mode) {
var expendedCmd = "sudo -H -u " + sys_user + " bash -c \'" + cmd + "\'";
try {
if (mode == 'sync') {
child_process.execSync(expendedCmd, (err, stdout, stderr) => {
if (err) {
logger.info(err);
return;
}
logger.info(stdout);
logger.info(stderr);
});
}
else {
logger.info("mode other than sync is not supported now.");
throw new Error("mode other than sync is not supported now.");
}
}
catch (error) {
console.log("Something wrong with exit code: " + error.status)
return error.status;
}
return 0;
}