调用函数时候,传入脚本路径名称或者具体命令。

int shell_call(std::string &cmdstr) {
  enum { maxline= };
  char line[maxline];
  FILE *fpin;
  int ret;
  if((fpin = popen(cmdstr.c_str(), "r")) == NULL) {
    printf("popen error\n");
    exit(-);
  }
  for(;;) {
    fputs("prompt> ", stdout);
    fflush(stdout);
    if(fgets(line, maxline, fpin) == NULL) /*read from pipe*/
      break;
    if(fputs(line, stdout) == EOF) {
      printf("fputs error\n");
      exit(-);
    }
  }
  if((ret = pclose(fpin)) == -) {
    printf("pclose error\n");
    exit(-);
  }
  return ret;
}

C++调用shell脚本的更多相关文章

  1. 【原】Gradle调用shell脚本和python脚本并传参

    最近由于项目自动化构建的需要,研究了下gradle调用脚本并传参的用法,在此作个总结. Pre build.gradle中定义了$jenkinsJobName $jenkinsBuild两个Jenki ...

  2. 调用shell脚本,IP处理

    //调用shell脚本,IP处理 package com.letv.sdns.web.utils; import org.slf4j.Logger; import org.slf4j.LoggerFa ...

  3. C程序调用shell脚本共有三种方法

    C程序调用shell脚本共有三种法子 :system().popen().exec系列函数call_exec1.c ,内容为:system() 不用你自己去产生进程,它已经封装了,直接加入自己的命令e ...

  4. Java 调用 shell 脚本详解

    这一年的项目中,有大量的场景需要Java 进程调用 Linux的bash shell 脚本实现相关功能. 从之前的项目中拷贝的相关模块和网上的例子来看,有个别的“陷阱”造成调用shell 脚本在某些特 ...

  5. python调用shell脚本时需要切换目录

    最近遇到了一个问题,就是python代码调用shell脚本时,发现输入输出的文件,总是和自己预想的有偏差,但是单独在linux下执行命令的时候,却没有错误.后来发现是相对路径的问题,因为执行pytho ...

  6. python调用shell脚本

    # coding=utf-8   //设置文本格式import os            //导入os方法print('hello')n=os.system('/home/csliyb/kjqy_x ...

  7. Centos下使用php调用shell脚本

    我们在实际项目中或许会遇到php调用shell脚本的需求.下面就用简单案例在Centos环境下实践 准备 查看php.ini中配置是否打开安全模式 //php.ini safe_mode = //这个 ...

  8. Android应用程序如何调用shell脚本(一)

    转自: Android应用程序如何调用shell脚本(一) 一般来说, Android 下的应用程序可以“直接”得到的最大的权限为 system ,但是如果我们需要在程序中执行某些需要 root 权限 ...

  9. 用java代码调用shell脚本执行sqoop将hive表中数据导出到mysql

    1:创建shell脚本 touch sqoop_options.sh chmod 777 sqoop_options.sh 编辑文件  特地将执行map的个数设置为变量  测试 可以java代码传参数 ...

  10. Python 调用 Shell脚本的方法

    Python 调用 Shell脚本的方法 1.os模块的popen方法 通过 os.popen() 返回的是 file read 的对象,对其进行读取 read() 的操作可以看到执行的输出. > ...

随机推荐

  1. linux启动时开启screen

    编辑/etc/rc.local 添加 su - ubuntu -c 'screen -dmS ss zserver -p /etc/config'

  2. react 子组件给父组件传值

    import React from 'react'import '../page1/header.css'import { Table } from 'antd'import Child from ' ...

  3. inet_XX族函数

    在网络编程中, 经常会将网络字节转为本地字节或者将本地字节转为网络字节, 但是如果每次我们都是都通过htonl, ntohl函数需要将10进制转为整数, 甚至还用将字符串转为整数, 再转为网络字节, ...

  4. 【数据结构】C语言栈的基本操作

    #include<stdio.h> #include<stdlib.h> #include<malloc.h> //定义节点 struct Node { int d ...

  5. scrapy——8 scrapyd使用

    scrapy——8    scrapyd使用 什么是scrapyd 怎么安装scrapyd 如何使用scrapyd--运行scrapyd 如何使用scrapyd--配置scrapy.cfg 如何使用s ...

  6. 如何应对SHA-1加密算法升级为SHA-256

    经过权威机构证实,sha1加密算法的不安全性越来越高,sha指纹造假成本越来越低,随即微软.谷歌等IT巨头相继发布弃用sha1加密算法声明,第三方认证机构自2016年1月1日起,将全面停止签发SHA1 ...

  7. 【 Educational Codeforces Round 51 (Rated for Div. 2) F】The Shortest Statement

    [链接] 我是链接,点我呀:) [题意] [题解] 先处理出来任意一棵树. 然后把不是树上的边处理出来 对于每一条非树边的点(最多21*2个点) 在原图上,做dijkstra 这样就能处理出来这些非树 ...

  8. 【[Offer收割]编程练习赛12 A】歌德巴赫猜想

    [题目链接]:http://hihocoder.com/problemset/problem/1493 [题意] [题解] 枚举P从2..n/2 如果P是质数且N-P也是质数; 则输出P和N-P就好; ...

  9. 清北学堂模拟赛d3t6 c

    分析:比较神奇的一道题.要把树变成环肯定要先变成链,然后把链给拼接成环.接下来考虑一个脑洞大开的树形dp:设f[i][0]表示i不与父节点相连的链数,f[i][1]表示i与父节点相连的链数,先考虑怎么 ...

  10. hdu 2527哈夫曼树(二叉树的运用)

    #include<stdio.h> #include<string.h> #define N  100 #define INF  2000000000  int b[N]; c ...