[请问]可不可以在C中调用shell命令?
-
- 帖子: 166
- 注册时间: 2007-12-26 11:02
[请问]可不可以在C中调用shell命令?
如:
在main中能还直接使用pwd???
在main中能还直接使用pwd???
- bones7456
- 帖子: 8495
- 注册时间: 2006-04-12 20:05
- 来自: 杭州
- 联系:
- eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
-
- 帖子: 122
- 注册时间: 2006-11-26 14:41
-
- 帖子: 166
- 注册时间: 2007-12-26 11:02
可能是我表达有误,我不是想得到当然目录,我是想使用这个命令.bones7456 写了:代码: 全选
lily@LLY:~/test$ cat fopen.c #include<stdio.h> int main(){ FILE * fp; char str[1024]; if(NULL==(fp=popen("pwd","r"))){ return -1; }else{ printf("%s",fgets(str,1023,fp)); } return 0; } lily@LLY:~/test$ gcc fopen.c lily@LLY:~/test$ ./a.out /home/lily/test lily@LLY:~/test$
-
- 帖子: 166
- 注册时间: 2007-12-26 11:02
-
- 帖子: 166
- 注册时间: 2007-12-26 11:02
- 79hy
- 帖子: 80
- 注册时间: 2007-10-24 10:21
- 来自: 长沙
手册说调用popen函数的时候要fflush一下,这里是fflush stdin or stdout???bones7456 写了:代码: 全选
lily@LLY:~/test$ cat fopen.c #include<stdio.h> int main(){ FILE * fp; char str[1024]; if(NULL==(fp=popen("pwd","r"))){ return -1; }else{ printf("%s",fgets(str,1023,fp)); } return 0; } lily@LLY:~/test$ gcc fopen.c lily@LLY:~/test$ ./a.out /home/lily/test lily@LLY:~/test$
- bones7456
- 帖子: 8495
- 注册时间: 2006-04-12 20:05
- 来自: 杭州
- 联系:
晕,这样就是使用了这个命令啊....xxmv99 写了:可能是我表达有误,我不是想得到当然目录,我是想使用这个命令.bones7456 写了:代码: 全选
lily@LLY:~/test$ cat fopen.c #include<stdio.h> int main(){ FILE * fp; char str[1024]; if(NULL==(fp=popen("pwd","r"))){ return -1; }else{ printf("%s",fgets(str,1023,fp)); } return 0; } lily@LLY:~/test$ gcc fopen.c lily@LLY:~/test$ ./a.out /home/lily/test lily@LLY:~/test$
关注我的blog: ε==3
- bones7456
- 帖子: 8495
- 注册时间: 2006-04-12 20:05
- 来自: 杭州
- 联系: