標籤:win process logs 應用 std pre until str .cpp
使用C調用python -m pydoc指令,實現命令列直接使用pydoc
1 // Win32Project1.cpp : 定義控制台應用程式的進入點。 2 // 3 4 5 #include <stdio.h> 6 #include <stdlib.h> 7 #include<string.h> 8 9 int main(int argc,char *argv[])10 {11 12 char psBuffer[128];13 FILE *pPipe;14 15 /* Run DIR so that it writes its output to a pipe. Open this16 * pipe with read text attribute so that we can read it17 * like a text file.18 */19 char py[100] = "python3 -m pydoc ";20 if (argv[1])21 {22 strcat(py, argv[1]);23 //printf("%s",py);24 }25 26 if ((pPipe = _popen(py, "rt")) == NULL)27 exit(1);28 29 /* Read pipe until end of file, or an error occurs. */30 31 while (fgets(psBuffer, 128, pPipe))32 {33 printf(psBuffer);34 }35 36 /* Close pipe and print return value of pPipe. */37 if (feof(pPipe))38 {39 printf("\nProcess returned %d\n", _pclose(pPipe));40 }41 else42 {43 printf("Error: Failed to read the pipe to the end.\n");44 }45 46 }
Windows下的pydoc