From: Bryan B. <br...@bu...> - 2012-04-17 12:13:53
|
> > > > ----- Original Message ----- >> From: Bryan Bueter <br...@bu...> >> To: exp...@li... >> Cc: >> Sent: Monday, April 16, 2012 9:20 PM >> Subject: [Expectperl-discuss] Yet Another Threading Example >> >> Ok, still playing around with threading on top of Expect, and I've >> designed what I think is a pretty good solution. However there is much >> I >> dont understand and I'm looking for feedback to make sure i'm not doing >> something inherently wrong. >> >> The way I've been able to do this is by pre-allocating pty's for jobs >> I'm >> going to need, in this case i'm ssh'ing so i need one pty per host. >> >> After the pty's are set up, i fork off one or more worker process who >> reads in a list of command from a pipe. When the worker gets a hostname >> it then forks another process who ties STDIN/OUT/ERR to the pty for that >> host and exec's the ssh command. > > Have you considered using Net::OpenSSH or Net::OpenSSH::Parallel? > > I'm not really trying to execute a parallel ssh, i'm trying to use expect within a thread. The example was arbitrary, you could Expect any command you wanted in this way. I'm simply looking for technical concerns related to the implementation. For example, in the "try" script bundled with IO::Tty, the parent process "syncs" with the exec by using a pipe: --> pipe(STAT_RDR, STAT_WTR) or die "Cannot open pipe: $!"; STAT_WTR->autoflush(1); $pid = fork(); die "Cannot fork" if not defined $pid; unless ($pid) { ... # Set up STDIN/OUT/ERR stuff { exec(@ARGV) }; print STAT_WTR $!+0; die "Cannot exec(@ARGV): $!"; } close STAT_WTR; $pty->close_slave(); $pty->set_raw(); # now wait for child exec (eof due to close-on-exit) or exec error my $errstatus = sysread(STAT_RDR, $errno, 256); die "Cannot sync with child: $!" if not defined $errstatus; close STAT_RDR; <-- I dont do any kind of sync in my example. Is that an issue? It doesnt appear to cause me any grief however I'm not sure what happens when I read from $pty before the child finishes setting it up. Thanks Bryan Bueter |