- 论坛徽章:
- 7
|
int
getCom(char *mycomm)
{
char *tokcom;
char command[256];
FILE *getcom;
memset(command,0,256);
tokcom = malloc(64);
memset (tokcom, 0, 64);
syslog(LOG_WARNING, "=====getCom begin====");
sprintf(command,"%s", mycomm);
syslog(LOG_WARNING, "=====comm : %s====", mycomm);
syslog(LOG_WARNING, "=====command: %s====", command);
if ((getcom = popen (command, "r")) == NULL)
{
pclose (getcom);
free (tokcom);
syslog(LOG_WARNING, "=====getcom 1====");
return -1;
}
else
{
sleep(1);
size_t len = read (fileno (getcom),tokcom,64);
syslog(LOG_WARNING, "=====len : %d====", len);
syslog(LOG_WARNING, "=====tokcom : %s====", tokcom);
syslog(LOG_WARNING, "=====getcom 2====");
pclose (getcom);
free (tokcom);
return 0;
}
return 0;
syslog(LOG_WARNING, "=====getcom end====");
}
popen的代码 |
|