Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Process stdout of running process

Moderators: larsivi kris

Posted: 07/17/09 17:34:55

Hi, I'm trying to read the output from a tango.sys.Process instance. But if the process exits i can easily look at the output in Process.stdout, if it does not exit and does not print too much lines, i get no output. For example look at this code:

module main;

import tango.sys.Process;

int main(){
	auto p = new Process("hcidump", null);
	foreach (line; new Lines!(char)(p.stdout))

	return 0;

hcidump needs root privileges, or it exits. If i run with a normal user i get the stdout printed, if i run the program as root i don't get anything. Note that hcidump writes on stdout information about each buetooth packet received.

How can i access each line of hcidump stdout? thx.

Author Message

Posted: 07/17/09 22:07:03

When console IO is redirected, Stdout does not automatically flush each line of buffered output. This may be the issue? See module for the control mechanism (Stdout is an instance of FormatOutput):

final FormatOutput flush (bool yes)

Posted: 07/18/09 07:10:43

as kris is saying this is most likely a flush issue, the safest thing is to use explicit flush at the point that you want to send.

Posted: 07/20/09 14:32:53

Yep it was a flushing problem, solved now. thx kris and fawzi