Chinaunix首页 | 论坛 | 博客
  • 博客访问: 498927
  • 博文数量: 110
  • 博客积分: 3971
  • 博客等级: 中校
  • 技术积分: 1175
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-20 23:27
文章分类

全部博文(110)

文章存档

2015年(2)

2014年(1)

2013年(1)

2011年(9)

2010年(28)

2009年(12)

2008年(13)

2007年(23)

2006年(21)

我的朋友

分类: WINDOWS

2013-12-24 11:01:42

system(执行shell   命令)     
表头文件     #include  
  
定义函数     int   system(const   char   *   string); 
  
函数说明     system()会调用fork()产生子进程,由子进程来调用/bin/sh-c   string来执行参数string字符串所代表的命令,此命令执行完后随即返回原调用的进程。在调用system()期间SIGCHLD   信号会被暂时搁置,SIGINT和SIGQUIT   信号则会被忽略。 
  
返回值     如果system()在调用/bin/sh时失败则返回127,其他失败原因返回-1。若参数string为空指针(NULL),则返回非零值。如果 system()调用成功则最后会返回执行shell命令后的返回值,但是此返回值也有可能为system()调用/bin/sh失败所返回的127,因 此最好能再检查errno   来确认执行成功。 
  
附加说明     在编写具有SUID/SGID权限的程序时请勿使用system(),system()会继承环境变量,通过环境变量可能会造成系统安全的问题。 
  
范例     #include  
main() 

system(“ls   -al   /etc/passwd   /etc/shadow”); 
}


###  多个系统调用
#include
int main()
{
    system("start F:\\uTorrent\\uTorrent.exe");
    system("start closeLCD.exe");
    system("start srun3000.exe");
    system("start F:\\TTPlayer\\TTPlayer.exe");
    system("start D:\\Tencent\\Bin\\QQ.exe");
    return 0;
}

阅读(737) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~