The following snippet uses perl to automatically find the right /dev/pts/? The biggest obstacle is getting the right pid. When you open an xterm you can get it's pid from "fork()", but then it starts bash which is another pid. I have used time() to tag the xterm so it can be found and used as the parent pid of the bash instance. The ttydev is connected to the bash pid, not the xterm pid. Otherwise, it's straight forward.
#!/usr/bin/perl use warnings; use strict; use Proc::ProcessTable; my $time = time(); my $xtermparentpid; my $pttydev; system("xterm -T $time &"); #specify title so you can match for it my $t = new Proc::ProcessTable; foreach my $p (@{$t->table}) { # print "pid->",$p->pid," ttydev->",$p->ttydev," cmdline->", # $p->cmndline," ppid->",$p->ppid,"\n"; if($p->cmndline =~ /$time/){$xtermparentpid = $p->pid} } foreach my $p (@{$t->table}) { if($p->ppid == $xtermparentpid){$pttydev = $p->ttydev} } open(FH,">$pttydev") or warn $!; for(1..1000){print STDOUT $_,"\n"; print FH $_.'a',"\n";sleep 1;} close FH;
|
|---|