문제

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