Created
March 4, 2020 07:42
-
-
Save ksvbka/903df4745b684b10b2c2268c69eb9731 to your computer and use it in GitHub Desktop.
Get output from stdout when execute a command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.0 | |
import QtQuick.Controls 1.0 | |
import QtQuick.Layouts 1.0 | |
import org.kde.plasma.core 2.0 as PlasmaCore | |
Item { | |
implicitWidth: label.implicitWidth | |
implicitHeight: label.implicitHeight | |
property string data: "?" | |
PlasmaCore.DataSource { | |
id: executable | |
engine: "executable" | |
connectedSources: [] | |
onNewData: { | |
var exitCode = data["exit code"] | |
var exitStatus = data["exit status"] | |
var stdout = data["stdout"] | |
var stderr = data["stderr"] | |
exited(exitCode, exitStatus, stdout, stderr) | |
disconnectSource(sourceName) // cmd finished | |
} | |
function exec(cmd) { | |
connectSource(cmd) | |
} | |
signal exited(int exitCode, int exitStatus, string stdout, string stderr) | |
} | |
Connections { | |
target: executable | |
onExited: { | |
data = stdout.replace('\n', ' ').trim() | |
} | |
} | |
Label { | |
id: label | |
text: i18n("<b>ls -la\n:</b> %1", data) | |
} | |
Component.onCompleted: { | |
var cmd = 'ls -la' | |
executable.exec(cmd) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment