ソースを参照

Fixed error messages

master
Pradeep Bhaskaran 4年前
コミット
a6ee6d33f8
1個のファイルの変更24行の追加20行の削除
  1. 24
    20
      index.js

+ 24
- 20
index.js ファイルの表示

@@ -99,7 +99,7 @@ var isRunningElevated = ()=>{
return nodeShellExec( "fsutil", ["dirty", "query", "C:"], {
inherit : true
// , shell: true
// , stdio: 'ignore'
, stdio: 'ignore'
, env: process.env
, title : `check privileged execution mode using "fsutil dirty query C:"`
}).then((exitcode)=>{
@@ -274,7 +274,7 @@ var __runcmd = function(label){
}
)
.catch(()=>{
console.log('Not Elevated Requesting Elevated Privileges');
console.log('Requesting Elevated Privileges');
// Wait for the runas to complete before we read it.
try {
fs.unlinkSync('run.done')
@@ -300,7 +300,7 @@ var __runcmd = function(label){
// runas returned.
var runaslog = JSON.parse('[ { "success" : true, "result" : "runas Log" }' + fs.readFileSync('run.log', { flags : 'a+'}) + ']');
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));
@@ -687,24 +687,28 @@ function nodeShellExec() {
var p = new Promise(function(resolve, reject){
if(!opts.detached) {
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) => {
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)
resolve(true)

読み込み中…
キャンセル
保存