Skip to main content
added 6 characters in body
Source Link
Andrew Truckle
  • 19.4k
  • 17
  • 93
  • 231

I want to run 'netstat -ano'netstat -ano command using popenpopen.

And I want to show the result of executing the command through mfc list controlMFC List Control.

Run the following code from the win32 console project and it will run correctly.

However, if run it on mfcMFC project, popen("netstat -ano *.c","r") result is nullnull.

The development environment is VC6.0.

Please let me know why nullnull is coming. Thank you :)

FILE *fp = NULL; char line[10240]; char* network[5]; int nIndexNetwork = 0; if( (fp=popen("netstat -ano *.c","r")) == NULL) { printf("[%d:%s]\n", errno, strerror(errno)); CString str; str.Format("%d",errno); GetDlgItem(IDC_EDIT1)->SetWindowText(str); return 1; } while(fgets(line, 10240, fp) != NULL) { char *word = strtok(line, " "); while (word != NULL) // 자른 문자열이 나오지 않을 때까지 반복 { network[nIndexNetwork] = word; nIndexNetwork++; printf("%s\n", network[nIndexNetwork-1]); // 자른 문자열 출력 word = strtok(NULL, " "); // 다음 문자열을 잘라서 포인터를 반환 } nIndexNetwork = 0; m_ctlList_network.AddItem(network[4], network[0], network[1], network[2], network[3]); } pclose(fp); return 0; 

I want to run 'netstat -ano' command using popen.

And I want to show the result of executing the command through mfc list control.

Run the following code from the win32 console project and it will run correctly.

However, if run it on mfc project, popen("netstat -ano *.c","r") result is null.

The development environment is VC6.0.

Please let me know why null is coming. Thank you :)

FILE *fp = NULL; char line[10240]; char* network[5]; int nIndexNetwork = 0; if( (fp=popen("netstat -ano *.c","r")) == NULL) { printf("[%d:%s]\n", errno, strerror(errno)); CString str; str.Format("%d",errno); GetDlgItem(IDC_EDIT1)->SetWindowText(str); return 1; } while(fgets(line, 10240, fp) != NULL) { char *word = strtok(line, " "); while (word != NULL) // 자른 문자열이 나오지 않을 때까지 반복 { network[nIndexNetwork] = word; nIndexNetwork++; printf("%s\n", network[nIndexNetwork-1]); // 자른 문자열 출력 word = strtok(NULL, " "); // 다음 문자열을 잘라서 포인터를 반환 } nIndexNetwork = 0; m_ctlList_network.AddItem(network[4], network[0], network[1], network[2], network[3]); } pclose(fp); return 0; 

I want to run netstat -ano command using popen.

And I want to show the result of executing the command through MFC List Control.

Run the following code from the win32 console project and it will run correctly.

However, if run it on MFC project, popen("netstat -ano *.c","r") result is null.

The development environment is VC6.0.

Please let me know why null is coming. Thank you :)

FILE *fp = NULL; char line[10240]; char* network[5]; int nIndexNetwork = 0; if( (fp=popen("netstat -ano *.c","r")) == NULL) { printf("[%d:%s]\n", errno, strerror(errno)); CString str; str.Format("%d",errno); GetDlgItem(IDC_EDIT1)->SetWindowText(str); return 1; } while(fgets(line, 10240, fp) != NULL) { char *word = strtok(line, " "); while (word != NULL) // 자른 문자열이 나오지 않을 때까지 반복 { network[nIndexNetwork] = word; nIndexNetwork++; printf("%s\n", network[nIndexNetwork-1]); // 자른 문자열 출력 word = strtok(NULL, " "); // 다음 문자열을 잘라서 포인터를 반환 } nIndexNetwork = 0; m_ctlList_network.AddItem(network[4], network[0], network[1], network[2], network[3]); } pclose(fp); return 0; 
Source Link
areum
  • 103
  • 3
  • 15

c++ - The result of popen is null

I want to run 'netstat -ano' command using popen.

And I want to show the result of executing the command through mfc list control.

Run the following code from the win32 console project and it will run correctly.

However, if run it on mfc project, popen("netstat -ano *.c","r") result is null.

The development environment is VC6.0.

Please let me know why null is coming. Thank you :)

FILE *fp = NULL; char line[10240]; char* network[5]; int nIndexNetwork = 0; if( (fp=popen("netstat -ano *.c","r")) == NULL) { printf("[%d:%s]\n", errno, strerror(errno)); CString str; str.Format("%d",errno); GetDlgItem(IDC_EDIT1)->SetWindowText(str); return 1; } while(fgets(line, 10240, fp) != NULL) { char *word = strtok(line, " "); while (word != NULL) // 자른 문자열이 나오지 않을 때까지 반복 { network[nIndexNetwork] = word; nIndexNetwork++; printf("%s\n", network[nIndexNetwork-1]); // 자른 문자열 출력 word = strtok(NULL, " "); // 다음 문자열을 잘라서 포인터를 반환 } nIndexNetwork = 0; m_ctlList_network.AddItem(network[4], network[0], network[1], network[2], network[3]); } pclose(fp); return 0;