LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1451|回复: 2

C 问题(help)

[复制链接]
发表于 2002-8-29 14:10:56 | 显示全部楼层 |阅读模式
请问是否可以在 C 程序中嵌入 shell script ( 或者 shell 命令 )? 如可以,请问如何做,谢了先!!!!!
发表于 2002-8-29 18:15:50 | 显示全部楼层
先写好sh程序,并在shell下可执行。在C中可以用system()执行它。
举例如下:
$cat  mysh
-----------------------------------------------------------------
#!sh
#
# this test program for C call
echo "this is shell"
-------------------------------------------------------------------
cat callsh.c
/*********************************************
*
* the program is call myshell
*
*********************************************/
#include <stdio.h>
int main()
{
     printf("\nthis is C program!\n");
     system("mysh");
      return 0;
}
 楼主| 发表于 2002-8-29 23:24:50 | 显示全部楼层
非常非常感谢!!!!!!!!!!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表