首页 > 代码库 > Windows下的pydoc

Windows下的pydoc

使用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 this
16     * pipe with read text attribute so that we can read it
17     * 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     else
42     {
43         printf("Error: Failed to read the pipe to the end.\n");
44     }
45     
46 }

 

Windows下的pydoc