Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,872 questions

51,796 answers

573 users

How to read all the standard output from the process in C

1 Answer

0 votes
#include <stdio.h>

void print(FILE *fp)
{
    int c;
    while ((c = getc(fp)) != EOF)
        putchar(c);
}
int main(void)
{
    FILE *fp;

    if ((fp = popen("netstat", "r")) == NULL)
        return 1;
  
    print(fp);
    
    pclose(fp);
    
    return 0;
}
    
/*
run:
 

Active Connections

  Proto  Local Address          Foreign Address        State
  TCP    127.0.0.1:....         Avi-PC:.....           ESTABLISHED
  TCP    123.456.9.789:.....    fw-okpk123:https       ESTABLISHED
  TCP    123.456.9.789:.....    mmpb:imap              ESTABLISHED
  ...
  
*/

 



answered Aug 19, 2017 by avibootz
...