Browse Source

Fixed error messages

master
Pradeep Bhaskaran 4 years ago
parent
commit
a6ee6d33f8
1 changed files with 24 additions and 20 deletions
  1. 24
    20
      index.js

+ 24
- 20
index.js View File

return nodeShellExec( "fsutil", ["dirty", "query", "C:"], { return nodeShellExec( "fsutil", ["dirty", "query", "C:"], {
inherit : true inherit : true
// , shell: true // , shell: true
// , stdio: 'ignore'
, stdio: 'ignore'
, env: process.env , env: process.env
, title : `check privileged execution mode using "fsutil dirty query C:"` , title : `check privileged execution mode using "fsutil dirty query C:"`
}).then((exitcode)=>{ }).then((exitcode)=>{
} }
) )
.catch(()=>{ .catch(()=>{
console.log('Not Elevated Requesting Elevated Privileges');
console.log('Requesting Elevated Privileges');
// Wait for the runas to complete before we read it. // Wait for the runas to complete before we read it.
try { try {
fs.unlinkSync('run.done') fs.unlinkSync('run.done')
// runas returned. // runas returned.
var runaslog = JSON.parse('[ { "success" : true, "result" : "runas Log" }' + fs.readFileSync('run.log', { flags : 'a+'}) + ']'); var runaslog = JSON.parse('[ { "success" : true, "result" : "runas Log" }' + fs.readFileSync('run.log', { flags : 'a+'}) + ']');
runaslog.forEach((logEntry)=>{ runaslog.forEach((logEntry)=>{
logEntry.succes ? (console.log(['success :' + logEntry.result]), console.log((logEntry.messages || []).join(' '))) : console.error(['error :' + logEntry.result]), console.error((logEntry.messages || []).join(' '))
logEntry.success ? (console.log(['success :' + logEntry.result]), console.log((logEntry.messages || []).join(' '))) : console.error(['error :' + logEntry.result]), console.error((logEntry.messages || []).join(' '))
}) })
}) })
.catch(err => console.error('Elevation failed : ' + err)); .catch(err => console.error('Elevation failed : ' + err));
var p = new Promise(function(resolve, reject){ var p = new Promise(function(resolve, reject){
if(!opts.detached) { if(!opts.detached) {
var messages = []; // PB : TODO -- Explore stream for Task level aggregation to prevent interleaved messages from multiple tasks... var messages = []; // PB : TODO -- Explore stream for Task level aggregation to prevent interleaved messages from multiple tasks...
var succes = true;
// use child.stdout.setEncoding('utf8'); if you want text chunks
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
child.stdout.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/});
child.on('error', (chunk) => { succes = false; messages.push(chunk); /*console.error(chunk)*/ });
child.stderr.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/});
// child.stderr.pipe(process.stderr);
var success = true;
if(opts.stdio !== 'ignore') {
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
child.stdout.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/});
child.on('error', (chunk) => { success = false; messages.push(chunk); /*console.error(chunk)*/ });
child.stderr.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/});
}
child.on('close', (code) => { child.on('close', (code) => {
if(code !== 0) succes = false;
if(opts.runas){
fs.writeFileSync('run.log', ', ' + JSON.stringify({ result: ` ${opts.title} exited with code ${code}`, messages : messages }), {'flag':'a+'} )
}
else {
succes ? console.log(['success : ' + ` ${opts.title} exited with code ${code}`]) : console.error([`error : ${opts.title} exited with code ${code}`])
// console.log( messages.join('') )
process.stdout.write( messages.join('') )
if(+code !== 0) success = false;
if(opts.stdio !== 'ignore') {
if(opts.runas){
var logEntry = { result: `${opts.title} exited with code ${code}`, messages : messages }
success ? logEntry.success = true : null;
fs.writeFileSync('run.log', ', ' + JSON.stringify(logEntry), {'flag':'a+'} )
}
else {
success ? console.log(['success : ' + ` ${opts.title} exited with code ${code}`]) : console.error([`error : ${opts.title} exited with code ${code}`])
// console.log( messages.join('') )
process.stdout.write( messages.join('') )
}
} }
if(code !== 0) return reject(code) if(code !== 0) return reject(code)
resolve(true) resolve(true)

Loading…
Cancel
Save