由于我在做linux下的QT开发,有时候会用到shell脚本的辅助,但是需要QT运行shell脚本并获取执行结果,今天给大家分享下我的技巧,废话少说直接上代码:

//执行shell指令或者shell脚本的方法
QString Common::executeLinuxCmd(QString strCmd)
{
QProcess p;
p.start("bash", QStringList() <<"-c" << strCmd);
p.waitForFinished();
QString strResult = p.readAllStandardOutput();
return strResult;
} //实例
QString strResult1 = executeLinuxCmd("sudo sh /home/test.sh"); QString strResult2 = executeLinuxCmd("cat /etc/hostname"); 大家根据自己的业务需求去处理strResult1和strResult2,相信我的代码很清晰了吧!!!

  

QT执行shell脚本或者执行linux指令的更多相关文章

  1. Linux中使用crontab命令定时执行shell脚本或其他Linux命令

    使用crontab你可以在指定的时间执行一个shell脚本或者一系列Linux命令.例如系统管理员安排一个备份任务使其每天都运行 如何往 cron 中添加一个作业? # crontab –e0 5 * ...

  2. Linux 定时执行shell脚本命令之crontab

    crontab可以在指定的时间执行一个shell脚本以及执行一系列Linux命令 例如:服务器管理员定时备份数据库数据.日志等 详解: 常用命令: crontab –e //修改 crontab 文件 ...

  3. Linux 下执行Shell 脚本的方式

    Shell 脚本的执行方式通常有如下三种: (1)bash script-name 或者 sh script-name:(2)path/script-name或者./script-name:(3)so ...

  4. Java 连接远程Linux 服务器执行 shell 脚本查看 CPU、内存、硬盘信息

    pom.xml jar 包支持 <dependency> <groupId>com.jcraft</groupId> <artifactId>jsch& ...

  5. Linux终端执行shell脚本,提示权限不够的解决办法

    原文:http://blog.csdn.net/this_capslock/article/details/17415409 今天在Linux尝试搭建dynamips的工作环境,在执行shell脚本时 ...

  6. Linux下如何执行Shell脚本

    Linux下你可以有两种方式执行Shell脚本: 1.用shell程序执行脚本:根据你的shell脚本的类型,选择shell程序,常用的有sh,bash,tcsh等(一般来说第一行#!/bin/bas ...

  7. Linux执行shell脚本方式及区别&命令后台运行

    Linux执行shell脚本方式及区别&命令后台运行 http://blog.csdn.net/heqiyu34/article/details/19089951/

  8. 在PHP中调用php_ssh实现远程登陆linux服务器并执行shell脚本。

    这个功能主要用于在web端利用程序对远程服务器进行操作,通过PHP_ssh执行shell脚本来实现. 首先要安装php_ssh2组件,linux中centos7下有ssh2源,直接安装.window下 ...

  9. linux执行shell脚本时提示bad interpreter:No such file or directory的解决办法

    故障现象:在终端直接cd /var正常,在shell脚本中执行则报错.原因是脚本是在windows平台下写的,换行符与Linux不同,造成脚本不能正确执行 出现bad interpreter:No s ...

随机推荐

  1. 淘宝适配 flexible.js

    1.引入 阿里cdm文件,也可以自己下载下来引用,不需要在添加<meta name="viewport"">标签了 <script src=" ...

  2. Windows环境下XAMPP的相关设置

    WINDOWS环境下多域名多端口配置:https://www.cnblogs.com/c-and-unity/p/4539348.html

  3. vuex简单使用。

    项目结构: 1:首先在项目中新建store.js文件,.js文件内容如下: import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) ex ...

  4. 2018HDU多校训练-3-Problem F. Grab The Tree

    Little Q and Little T are playing a game on a tree. There are n vertices on the tree, labeled by 1,2 ...

  5. CodeForces1006C-Three Parts of the Array

    C. Three Parts of the Array time limit per test 1 second memory limit per test 256 megabytes input s ...

  6. 【JS】376- Axios 使用指南

    点击上方"前端自习课"关注,学习起来~ 来源 | https://www.jianshu.com/p/df464b26ae58 一.axios    基于promise用于浏览器和 ...

  7. 机会来了!5G时代带来新闻传播行业的变革!

    5G时代到来!新闻传播行业大变革! 1.作为一名体育生进入的新闻传播学院,传统的新闻媒体能力已不再具有优势,意味着我有翻身的机会了! 从一开始进入大学,由于高中的知识储备不如其他人,尤其是英语能力方面 ...

  8. 首创诠释docker的Formulas: Windows 7 + Tiny Linux 4.19 + XFS + Vmware Workstation = super machine (docker从零开始时记,Follow me and you go)

    不少人从来没有接触过docker,或者仅仅是听说过,本文试图从原点开始深入了解docker的全貌,剖析docker的基础概念,让我们一起开始docker之旅~~~ 开场:什么是docker docke ...

  9. 7个点说清楚spring cloud微服务架构

    前言 spring cloud作为当下主流的微服务框架,让我们实现微服务架构简单快捷,spring cloud中各个组件在微服务架构中扮演的角色如下图所示,黑线表示注释说明,蓝线由A指向B,表示B从A ...

  10. VMware中Bridged、NAT、host-only三种网络连接模式的原理及其区别

    VMnet0:这是VMware用于虚拟桥接网络下的虚拟交换机: VMnet1:这是VMware用于虚拟Host-Only网络下的虚拟交换机: VMnet8:这是VMware用于虚拟NAT网络下的虚拟交 ...