Skip to content

Instantly share code, notes, and snippets.

@wateroot
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save wateroot/282580109fd062b37d80 to your computer and use it in GitHub Desktop.

Select an option

Save wateroot/282580109fd062b37d80 to your computer and use it in GitHub Desktop.
ExecPipeCmd
int ExecPipeCmd(char *szCmd)
{
FILE *pPipe = _popen(szCmd, "rt");
if (NULL == pPipe) {
//Log("_popen functio fail.\n");
return -1;
}
int nRet = -1;
CHAR szBuf[SOCK_BUF_SIZE] = {0};
while (fgets(szBuf, sizeof(szBuf), pPipe)) {
//send buf info to master.
nRet = send(g_hSock, szBuf, strnlen_s(szBuf, sizeof(szBuf)), 0);
if(nRet < 0) {
//Log("\nError occuerd while send data.");
break;
}
ZeroMemory(szBuf, sizeof(szBuf));
}
if (0 == _pclose(pPipe)) {
return 0;
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment