Solved

Pipe

Posted on 2001-06-21
1
453 Views
Last Modified: 2006-11-17
I have a Socket Server program which uses anonymous pipe to execute a command and get the results into a buffer. I followed these steps

Create anonymous pipe, Attach pipe's write end to the STDOUT.
Call system("command"),
Close write end of the pipe
Read from the pipe's read end
Close the read end of the pipe.

My problem is , every time I read from the pipe the previous output is still there. Say first time I have 100 bytes o/p, second time 30 bytes o/p. But when I read second time still I get 100 bytes (30 new + 70 old) I tried using FlushFileBuffers(), but no imporovements.

Instead of pipe I tried using _popen() function. It works fine, but it only gives me the STDOUT values to the buffer. But I also need the STDERR values if the command execution failed. But in pipes I use two pipes, one for STDOUT another for STDERR.

Could you please help me?  
Thanks in advance!
0
Comment
Question by:bkm
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 75 total points
ID: 6215078
Try to use the following command line with '_popen()':

command.com /c <your command> 2>&1

The last statement merges STDOUT with STDERR
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
undefined reference to `bswap_128' 9 161
How to set environment variables in C 2 82
C Language combined operators 28 109
How to learn Linux? 10 61
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question