博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c语言用命令行编译运行程序_使用C程序执行系统命令
阅读量:2529 次
发布时间:2019-05-11

本文共 1740 字,大约阅读时间需要 5 分钟。

c语言用命令行编译运行程序

Sometimes, we may need to execute / through our . (Note: the code given below is , so here we are testing Linux commands only).

有时,我们可能需要通过执行 / 。 (注意:下面给出的代码是 ,因此这里我们仅测试Linux命令)。

In the C programming standard library, there is a function named system () which is used to execute Linux as well as DOS commands in the C program.

在C编程标准库中,有一个名为system()的函数,该函数用于执行Linux以及C程序中的DOS命令。

A command can be assigned directly to the function as an argument and command may also input from the user and then assigned to the function, function will send command to the operating system’s particular terminal like Linux terminal or DOS commands terminal to execute, and after the execution, you will get your output and program’s execution returns to the next statement written after the system() function.

可以将命令作为参数直接分配给函数,也可以从用户输入命令,然后将其分配给函数,函数会将命令发送到操作系统的特定终端(例如Linux终端或DOS命令终端)以执行,然后执行,您将获得输出,程序的执行返回到在system()函数之后编写的下一条语句。

C中的system()函数 (system() function in C)

system() is a library function, which is defined in the stdlib.h header file. It is used to execute the Linux commands/Windows DOS commands.

system()是一个库函数,该函数在stdlib.h头文件中定义。 它用于执行Linux命令/ Windows DOS命令。

Syntax:

句法:

system(char *command);

Example:

例:

char *command = "ls";    system(command);

在C程序中运行Linux命令的程序 (Program to run Linux commands within C program)

#include 
#include
//to use system()#include
//to use strcpy()int main(){
char *command; //executing ls command strcpy(command, "ls"); printf("ls command...\n"); system(command); //executing date command strcpy(command, "date"); printf("date command...\n"); system(command); return 0;}

Output

输出量

Please run this program at your machine

翻译自:

c语言用命令行编译运行程序

转载地址:http://oatzd.baihongyu.com/

你可能感兴趣的文章
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_35、事务介绍和常见的隔离级别,传播行为...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_40、Redis工具类封装讲解和实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_37、分布式缓存Redis介绍...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_42、SpringBoot常用定时任务配置实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_39、SpringBoot2.x整合redis实战讲解...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第14节 高级篇幅之SpringBoot多环境配置_59、SpringBoot多环境配置介绍和项目实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_41、SpringBoot定时任务schedule讲解...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_43、SpringBoot2.x异步任务实战(核心知识)...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_1_01课程简介
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第11节 Logback日志框架介绍和SpringBoot整合实战_45、SpringBoot2.x日志讲解和Logback配置实战...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_1_02技术选型
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_汇总
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_2_01传统架构演进到分布式架构
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_2_02 微服务核心基础讲解
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_2_04微服务下电商项目基础模块设计...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_3-01 什么是微服务的注册中心
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_3-03CAP原理、常见面试题
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_3-04 SpringCloud微服务核心组件Eureka介绍和闭源后影响...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_3-05 服务注册和发现Eureka Server搭建实战...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_3-06 服务注册和发现之Eureka Client搭建商品服务实战...
查看>>