linux-c++调用shell
2016-04-25 16:12
465 查看
只要用system()就好.
如shell文件 first.sh
此shell程序的功能是把含有字符串“qiang”的文件都输出来。
c++文件 mycall.cpp
编译:
g++ mycall.cpp -o exe
执行
./exe
显示效果:
first
first.sh
hello.cpp
hello.cpp~
hzq.txt
mycall.cpp
mycall.cpp~
testdir.cpp
testdir.cpp~
如shell文件 first.sh
此shell程序的功能是把含有字符串“qiang”的文件都输出来。
#!/bin/bash # this file looks through all the files in the current directory for the string "qiang", and then prints the names of those files to the stand ouput for file in * do if grep -q qiang $file then echo $file fi done exit 0
c++文件 mycall.cpp
#include<iostream> #include<unistd.h> using namespace std; int main() { // system("./a.out"); system("sh first.sh"); }
编译:
g++ mycall.cpp -o exe
执行
./exe
显示效果:
first
first.sh
hello.cpp
hello.cpp~
hzq.txt
mycall.cpp
mycall.cpp~
testdir.cpp
testdir.cpp~
相关文章推荐
- shell练习-----猜数值
- Shell函数的简单应用
- Hbase入门API操作和 shell操作
- shell练习脚本
- adb shell删除Android系统下的软件
- Shell函数语法
- Shell 学习笔记
- shell基本指令
- MySQL 使用XtraBackup的shell脚本介绍
- shell分析nginx access log日志
- shell 脚本 指定用户执行命令
- linux下Bash编程循环语句特殊用法之编写脚本(十)
- HoloLens开发手记 - HoloLens shell概述 HoloLens shell overview
- bash: ifconfig: command not found
- 【Linux】使用SHELL脚本实时查看文件大小
- ipython是python的交互式shell工具
- Shell标准输出、标准错误 >/dev/null 2>&1
- Xen常用命令
- Jmeter ----Bean shell使用
- shell 笔记