سؤال

I am trying to parse each line produced by the following code with no luck.

if( !CreateProcess( NULL,   
    "netstat -an",        
    NULL,           
    NULL,           
    FALSE,          
    0,              
    NULL,           
    NULL,           
    &si,            
    &pi )           
)
{
    printf( "failed" );
    return 0;
}

Is there a way to read the output line by line and do something with each line? Thanks.

هل كانت مفيدة؟

المحلول

You do this by creating a pipe. Pass the write end of the pipe as the new process stdout. Read from the read end of the pipe. MSDN has a complete demonstration.

The code there shows you how to read the output from the child process. How to parse that into separate lines is a different issue. I believe that your main problem is just how to get hold of the output, and that parsing is something you already know how to do.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top