ÔÚC³ÌÐòÀïºÍshellͨÐÅ
Ò»°ãÎÒÃǵ÷ÓÃshell½Å±¾¶¼ÓÃsystem()À´ÊµÏÖ£¬È»ºó·¢ÏÖsytem·µ»ØÖµ²»ºÃ¿ØÖƶøÇÒת»»Âé·³(»¹ÒªÓÒÒÆ4λ¼´/256)£¬ÓÚÊÇÎÒÓÃpopenÀ´»ñÈ¡shellµÄ·µ»ØÖµ¡£¹ûÈ»ÔÚUnixÊÀ½çÀïÃæ£¬Í¨µÀ¾ÍÊÇÁ¬½á¸÷¸ö·½ÃæµÄÇÅÁº°¡£¡
´úÂëÀý×ÓÈçÏ£º
#include<stdio.h>
#include<stdlib.h>
#include<sys/wait.h>
int main (int argc, char *argv[])
{
char szline[256];
FILE *fp;
if (argc != 2)
{
printf ("usage: %s command\n", argv[0]);
return 0;
}
if ((fp = popen (argv[1], "r")) == NULL)
{
printf ("the command %s not exist\n", argv[1]);
return 0;
}
while (fgets (szline, sizeof (szline) - 1, fp) != NULL)
{
printf ("frome command:%s", szline);
}
pclose (fp);
return 0;
}
PS£ºÆæ¹ÖµÄÊÇÎÒÓÃÈçϺ¯Êý£º
char* get_cmd_result(char* cmd)
{
FILE *fp;
char result[256];
memset (result, 0,sizeof(result));
if((fp=popen(cmd,"r"))==NULL)
{
printf("the command %s not exist\n",cmd);
pclose(fp);
return 0;
}
while(fgets(result,sizeof(result)-1,fp)!=NULL)
{
#ifdef __DEBUG__
g_print("get result is %s\n", result);
#endif
}
pclose(fp);
return result;
}
ÔÚdebian sidϾÍûÎÊÌ⣬ÔÚUbuntu10.04Éϵ÷Óøú¯Êý¾Íû·¨·µ»ØµÄÕýÈ·Öµ£¬µ«ÔÚg¸Ãº¯ÊýÀïresultÊÇÕýÈ·µÄ£¬Õâ¸ö¾Í²»ÊǸÃÎÄÌÖÂÛµÄÎÊÌâÁË¡£
Ïà¹ØÎĵµ£º
1.ÇóÏÂÃæº¯ÊýµÄ·µ»ØÖµ£¨Î¢Èí£©
int func(x)
{
int countx = 0;
while(x)
{
countx ++;
x = x&(x-1);
......
[root@ocsser file]# cat array-05.c
//this is a program for two juzheng xiangcheng.
#include <stdio.h>
int main(){
int i,j,m,n;
int g,k,f;
int c[5][6];
& ......
2010Äê05ÔÂ1ºÅ |
23:15·ÖÀࣺ¹ÜÀíά»¤
, Õï¶Ï°¸Àý
| ±à¼
| ±êÇ©£º11g
¡¢dbca
¡¢netca
| 13
views
±¾Îijö×Ô “inthirties£¨ÄÐ
ÈËÈýÊ®£©
”²©¿Í£¬×ªÔØÇëÎñ±Ø×¢Ã÷×÷Õߺͱ£Áô³ö´¦¡£
¿Í»§×°ºÃÁËOracle£¬°²×°³É¹¦ÁË£ ......
51µ¥Æ¬»ú Keil C ÑÓʱ³ÌÐòµÄ¼òµ¥Ñо¿
by: InfiniteSpace Studio/isjfk, 1.21.2004
ÈκÎÈ˶¼¿ÉÒÔÔÚ×¢Ã÷Ô×÷Õߺͳö´¦µÄǰÌáÏÂËæÒâ×ªÔØÕâÆªÎÄÕ£¬µ«²»µÃÓÃÓÚÉÌҵĿµÄ¡£
......