Set working directories when doing exec().

Ylian Saint-Hilaire committed Apr 4, 2019 at 15:46 UTC 2c0c34cc91161c017594e348ab1cdb3cad80fc0e
2 files changed +7 -5
meshcentral.js
+6 -4
@@ -68,11 +68,13 @@ function CreateMeshCentralServer(config, args) {
68 if ((__dirname.endsWith('/node_modules/meshcentral')) || (__dirname.endsWith('\\node_modules\\meshcentral')) || (__dirname.endsWith('/node_modules/meshcentral/')) || (__dirname.endsWith('\\node_modules\\meshcentral\\'))) {
69 obj.datapath = obj.path.join(__dirname, '../../meshcentral-data');
70 obj.filespath = obj.path.join(__dirname, '../../meshcentral-files');
71 + obj.parentpath = obj.path.join(__dirname, '../..');
72 if (obj.fs.existsSync(obj.path.join(__dirname, '../../meshcentral-web/views'))) { obj.webViewsPath = obj.path.join(__dirname, '../../meshcentral-web/views'); } else { obj.webViewsPath = obj.path.join(__dirname, 'views'); }
73 if (obj.fs.existsSync(obj.path.join(__dirname, '../../meshcentral-web/public'))) { obj.webPublicPath = obj.path.join(__dirname, '../../meshcentral-web/public'); } else { obj.webPublicPath = obj.path.join(__dirname, 'public'); }
74 } else {
75 obj.datapath = obj.path.join(__dirname, '../meshcentral-data');
76 obj.filespath = obj.path.join(__dirname, '../meshcentral-files');
77 + obj.parentpath = obj.path.join(__dirname, '..');
78 if (obj.fs.existsSync(obj.path.join(__dirname, '../meshcentral-web/views'))) { obj.webViewsPath = obj.path.join(__dirname, '../meshcentral-web/views'); } else { obj.webViewsPath = obj.path.join(__dirname, 'views'); }
79 if (obj.fs.existsSync(obj.path.join(__dirname, '../meshcentral-web/public'))) { obj.webPublicPath = obj.path.join(__dirname, '../meshcentral-web/public'); } else { obj.webPublicPath = obj.path.join(__dirname, 'public'); }
80 }
@@ -163,7 +165,7 @@ function CreateMeshCentralServer(config, args) {
165 // Launch MeshCentral as a child server and monitor it.
166 obj.launchChildServer = function (startLine) {
167 var child_process = require('child_process');
166 - var xprocess = child_process.exec(startLine + ' --launch', { maxBuffer: Infinity }, function (error, stdout, stderr) {
168 + var xprocess = child_process.exec(startLine + ' --launch', { maxBuffer: Infinity, cwd: obj.parentpath }, function (error, stdout, stderr) {
169 if (xprocess.xrestart == 1) {
170 setTimeout(function () { obj.launchChildServer(startLine); }, 500); // This is an expected restart.
171 } else if (xprocess.xrestart == 2) {
@@ -175,7 +177,7 @@ function CreateMeshCentralServer(config, args) {
177 if (typeof obj.args.selfupdate == 'string') { version = '@' + obj.args.selfupdate; }
178 var child_process = require('child_process');
179 var npmpath = ((typeof obj.args.npmpath == 'string') ? obj.args.npmpath : 'npm');
178 - var xxprocess = child_process.exec(npmpath + ' install meshcentral' + version, { maxBuffer: Infinity, cwd: obj.path.join(__dirname, '../..') }, function (error, stdout, stderr) { });
180 + var xxprocess = child_process.exec(npmpath + ' install meshcentral' + version, { maxBuffer: Infinity, cwd: obj.parentpath }, function (error, stdout, stderr) { });
181 xxprocess.data = '';
182 xxprocess.stdout.on('data', function (data) { xxprocess.data += data; });
183 xxprocess.stderr.on('data', function (data) { xxprocess.data += data; });
@@ -205,7 +207,7 @@ function CreateMeshCentralServer(config, args) {
207 if (typeof obj.args.selfupdate == 'string') { callback(obj.currentVer, obj.args.selfupdate); return; } // If we are targetting a specific version, return that one as current.
208 var child_process = require('child_process');
209 var npmpath = ((typeof obj.args.npmpath == 'string') ? obj.args.npmpath : 'npm');
208 - var xprocess = child_process.exec(npmpath + ' view meshcentral dist-tags.latest', { maxBuffer: 512000 }, function (error, stdout, stderr) { });
210 + var xprocess = child_process.exec(npmpath + ' view meshcentral dist-tags.latest', { maxBuffer: 512000, cwd: obj.parentpath }, function (error, stdout, stderr) { });
211 xprocess.data = '';
212 xprocess.stdout.on('data', function (data) { xprocess.data += data; });
213 xprocess.stderr.on('data', function (data) { });
@@ -1646,7 +1648,7 @@ function InstallModule(modulename, func, tag1, tag2) {
1648 var child_process = require('child_process');
1649
1650 // Looks like we need to keep a global reference to the child process object for this to work correctly.
1649 - InstallModuleChildProcess = child_process.exec('npm install --no-optional --save ' + modulename, { maxBuffer: 512000, timeout: 10000 }, function (error, stdout, stderr) {
1651 + InstallModuleChildProcess = child_process.exec('npm install --no-optional --save ' + modulename, { maxBuffer: 512000, timeout: 10000, cwd: obj.parentpath }, function (error, stdout, stderr) {
1652 InstallModuleChildProcess = null;
1653 if (error != null) {
1654 console.log('ERROR: Unable to install required module "' + modulename + '". MeshCentral may not have access to npm, or npm may not have suffisent rights to load the new module. Try "npm install ' + modulename + '" to manualy install this module.\r\n');
package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.3.1-t",
3 + "version": "0.3.1-u",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",