www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - An implementation of popen/pclose

reply "Unknown W. Brackets" <unknown simplemachines.org> writes:
I was poking around a bit with a program that essentially used diff to 
find and parse changes in a file, and use them to generate output.  I 
looked through phobos for some sort of "ProcessStream" class... but 
there wasn't one - nor was there a popen.

Having experience with Linux and PHP... I like this function, when I 
need it (although obviously system calls aren't the best, and if I were 
serious I might write my own diffing routine instead of this obviously 
slower method.)  However, I also understand that the Windows 
implementation of it either does not work or does not work well.

So I wrote my own implementation, and while I was at it created a 
ProcessStream class as well.  I figured I'd post it here to see if I got 
any comments at all, and just in case it might help someone.  Note that 
it's not perfect, or anything.

To test it, simply use this and do a -unittest:

	import popen;

	int main()
		return 0;

(thought it's probably better form to use a more descriptive module name.)

I'm pretty sure it works on Windows 9x, but I didn't do any testing.

Jan 15 2005
parent Ben Hinkle <Ben_member pathlink.com> writes:
	// Seems this is private, so I had to override it; whether the file is open.
	private override bool isopen = false;
You can access the flag in the super class by calling isOpen to test the flag and close() to turn it to off. Calling close() will also reset the unget buffer. The one thing you can't do with the super class flag is turn it back on once it has been closed. For that reason probably the super class flag should be protected instead of private. -Ben
Jan 16 2005