使用C编程运行Shell脚本 [英] running shell script using c programming

查看:93
本文介绍了使用C编程运行Shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想问的一个问题是,我正在编写一个程序,其中必须使用c程序运行shell脚本.到现在为止,我已经把论点分开了.我已经搜索了exec应该用于运行shell脚本 但是我完全感到困惑,因为exec有很多变体,并且通过阅读手册页我找不到最合适的

hello every one I want to ask that I am making a program in which i have to run shell script using c program. up till now i have separated the arguments. and i have searched that exec should be use to run shell scripts but i am totally confused as there are many variants of exec and by reading the man pages i am unable to find which is best suitable

在某些exec函数中,第一个arg是

Also in some exec function first arg is

路径

有些有

指向文件的指针

pointer to file

有什么区别,我应该写些什么代替.请指导我 谢谢

what is the difference and what should i write in place of it.kindly guide me thanks

推荐答案

从C程序运行shell脚本通常使用

Running a shell script from a C program is usually done using

#include <stdlib.h>
int system (char *s);

其中s是指向脚本路径名的指针,例如

where s is a pointer to the pathname of the script, e.g.

int rc = system ("/home/username/bin/somescript.sh");

如果需要脚本的标准输出,请查看popen手册页.

If you need the stdout of the script, look at the popen man page.

这篇关于使用C编程运行Shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆