This is going to be long....just a warning.

First let me tell you how I got started on this. I'm working on some scripts that will autosubscribe users to calendars and folders. This will eventually be for 15000+ accounts. I originally started off by running a single zmprov command every time I wanted to perform some action, but that ends up being 3-5 zmprov commands per user and the open/run command/close time for each zmprov command was several seconds. OK for 10 users, not ok for 10,000. So I discovered that I could open a zmprov prompt once and then send it all the commands I wanted (sm, gaf, cf, etc...) for as many users as I wanted....and it would be super fast as I didn't have to keep opening and closing the zmprov prompt. So that's the background....here's the problem.

I'm writing my scripts in Ruby. It opens the zmprov prompt and then sends a series of commands (sm, gaf, cf, etc...), checks for output at each command, does something based on the output, and then move on to the next command. At least that's what I want it to do...

This is all well and good as long as I only check stdout. If I want to check both stdout and stderr....I start running into problems with blocking. It seems that zmprov is not releasing the pipe?/stream? on stdout/stderr so that the script gets control back...and so it sits and waits forever if I check stderr and no error was returned (i.e. the command worked)...or if I get an error then stdout is empty and blocks.

I've found and tried several different ways... IO.readpartial, threads (1 for each of stdin/stdout/stderr) with Open3.popen3, Open4.popen4(which has some threading built in). So far I've not found a single method that will let me do what I want...they all end up with blocking problems, or the output returned is not complete.

Apparently this is a difficult problem with zmprov not closing the stdout/stderr pipes until zmprov itself is closed.....so handling a ton of sm/gaf/cf/... output before closing zmprov for good is nigh impossible.

The only workaround I've come down to is to send my initial zmprov command like this 'zmprov 2>&1'... which will force both stdout/stderr to come through on stdout. Then I have to use some string matching to catch the errors manually by searching for the string 'ERROR:'. It's kind of kludgy and I don't normally like kludgy solutions if I can do it right in the first place....but it may be my only option since I can't seem to get it to work the right way. I have yet to try it though and prove that it works.

I'm just wondering if any ambitious scripters out there have figured a way around this so that they can send multiple commands through to zmprov and capture both stdout/stderr without blocking problems?

I can include code snippets if anyone is interested, but this is already pretty long.

Thanks,
Matt