Simplify syntax by a lot
parent
0c510483b8
commit
84306dcca0
@ -0,0 +1,12 @@
|
||||
function callProcess(binary, arguments, callback) {
|
||||
const component = Qt.createComponent("SimpleProcess.qml");
|
||||
if (component.status != Component.Ready) {
|
||||
if (component.status == Component.Error) {
|
||||
console.debug("Error:" + component.errorString());
|
||||
}
|
||||
throw new Error("Error:" + component.errorString());
|
||||
}
|
||||
const process = component.createObject(parent, {});
|
||||
process.onHasFinished.connect(callback);
|
||||
process.run(binary, arguments);
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
import QtQuick 2.0
|
||||
import Process 1.0
|
||||
|
||||
Process {
|
||||
property string binary
|
||||
property variant arguments
|
||||
|
||||
signal hasFinished(exitCode: int, stdout: string, stderr: string)
|
||||
signal hasSuccess(stdout: string, stderr: string)
|
||||
signal hasError(exitCode: int, stdout: string, stderr: string)
|
||||
signal stdout(stdout_chunk: string)
|
||||
signal stderr(stderr_chunk: string)
|
||||
|
||||
property string entire_stdout: ""
|
||||
property string entire_stderr: ""
|
||||
|
||||
id: process
|
||||
|
||||
function run(_binary: string, _arguments: variant){
|
||||
if(typeof _arguments == "string"){
|
||||
_arguments = [_arguments]
|
||||
}
|
||||
binary = _binary
|
||||
arguments = _arguments
|
||||
process.start(binary, arguments)
|
||||
}
|
||||
|
||||
onReadyRead: {
|
||||
let stdout_chunk = readAllStandardOutput()
|
||||
entire_stdout += stdout_chunk
|
||||
process.stdout(stdout_chunk)
|
||||
}
|
||||
|
||||
onFinished: {
|
||||
entire_stderr = readAllStandardError()
|
||||
if (exitCode === 0) {
|
||||
process.hasSuccess(entire_stdout, entire_stderr)
|
||||
} else {
|
||||
process.hasError(exitCode, entire_stdout, entire_stderr)
|
||||
}
|
||||
process.hasFinished(exitCode, entire_stdout, entire_stderr)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue