Qt中执行linux命令获取设备运行时间并返回结果
1.用shell脚本获取设备运行时间
#!bin/bash
cat /proc/uptime| awk -F
. '{run_days=$1 / 86400;
run_hour=($1 % 86400)/3600;
run_minute=($1 % 3600)/60;
run_second=$1 % 60;
printf("系统已运行:%d天%d时%d分%d秒",run_days,run_hour,run_minute,run_second)}'
2.Qt中执行linux中shell脚本并获取命令执行结果
static int getUpTime(int jid, Webs *wp, int argc, char **argv) {
QProcess process;
process.start("sh /opt/app/time.sh");
process.waitForFinished();
QByteArray output = process.readAllStandardOutput();
QString str_output = output;
websWrite(wp, "%s", str_output.toStdString().c_str());
return 0;
}