mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-30 04:42:45 +08:00
显示实时运行结果
This commit is contained in:
parent
f52053b763
commit
5b4ae6763f
@ -51,6 +51,7 @@ const QuickCommandActions = [
|
|||||||
simulatePaste();
|
simulatePaste();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// setTimout 不能在 vm2 中使用,同时在 electron 中有 bug
|
||||||
sleep = ms => {
|
sleep = ms => {
|
||||||
var start = new Date().getTime()
|
var start = new Date().getTime()
|
||||||
var cmd, tempFilePath
|
var cmd, tempFilePath
|
||||||
@ -130,37 +131,18 @@ runCodeInVm = (cmd, cb) => {
|
|||||||
return item.toString()
|
return item.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
var chunks = [], err_chunks = []
|
vm.on('console.log', stdout => {
|
||||||
|
cb(parseItem(stdout), null)
|
||||||
var callBackResult = () => {
|
|
||||||
cb(chunks.join("\n"), err_chunks.join("\n"))
|
|
||||||
}
|
|
||||||
|
|
||||||
vm.on('console.log', chunk => {
|
|
||||||
console.log(chunk);
|
|
||||||
chunks.push(parseItem(chunk))
|
|
||||||
});
|
});
|
||||||
|
|
||||||
vm.on('console.error', err_chunk => {
|
try {
|
||||||
err_chunks.push(err_chunk.toString())
|
vm.run(`
|
||||||
});
|
|
||||||
|
|
||||||
var timer = setInterval(() => {
|
|
||||||
if (process.exitcode == 1) {
|
|
||||||
console.log('done');
|
|
||||||
clearInterval(timer)
|
|
||||||
callBackResult()
|
|
||||||
}
|
|
||||||
}, 100);
|
|
||||||
|
|
||||||
vm.run(`
|
|
||||||
try {
|
|
||||||
${cmd}
|
${cmd}
|
||||||
} catch(e) {
|
process.exitcode = 1
|
||||||
console.error(e)
|
`, path.join(__dirname, 'preload.js'));
|
||||||
}
|
} catch (error) {
|
||||||
process.exitcode = 1
|
cb(null, error.toString())
|
||||||
`, path.join(__dirname, 'preload.js'));
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// shell 以环境变量下命令作为代码提示
|
// shell 以环境变量下命令作为代码提示
|
||||||
|
Loading…
x
Reference in New Issue
Block a user