From: Carlyle S. <car...@db...> - 2008-02-06 12:58:39
|
Hello, I am a system administrator in a large corporation which has not included Expect.pm and its siblings IO::Tty and IO::Stty in the packaging. I have written a perl script which creates a terminal for a child process which uses the terminal rather than standard IO; much as expect does but very simply and of very limited scope. This script works fine on AIX but not on SunOS or Linux. I need to know how to get the name of the slave side after opening the control side (/dev/ptc on AIX and /dev/ptmx on the others). On AIX ttyname does this for me but it returns "Inappropriate ioctl for device" elsewhere. I don't mean to take up time and space on this list but I have been looking unsuccessfully for a suitable mailing list more suited to my problem. Thank you for any pointers. Best regards, Carlyle -- Informationen (einschließlich Pflichtangaben) zu einzelnen, innerhalb der EU tätigen Gesellschaften und Zweigniederlassungen des Konzerns Deutsche Bank finden Sie unter http://www.db.com/de/content/pflichtangaben.htm. Diese E-Mail enthält vertrauliche und/ oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser E-Mail ist nicht gestattet. Please refer to http://www.db.com/en/content/eu_disclosures.htm for information (including mandatory corporate particulars) on selected Deutsche Bank branches and group companies registered or incorporated in the European Union. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. |
From: Roland G. <rgi...@cp...> - 2008-02-06 13:48:05
|
Can you post the relevant parts of the script? PTY-handling is hard, that's why IO::Tty is doing it in C. And you have no way of installing IO::Tty locally? If you worry about distribution, have a look at PAR, the Perl Archiver, on CPAN which lets you package required modules, even binary ones, with your script. Servus, Roland Carlyle Sutphen wrote: > Hello, > > I am a system administrator in a large corporation which > has not included Expect.pm and its siblings IO::Tty and IO::Stty > in the packaging. > > I have written a perl script which creates a terminal for a child > process which uses the terminal rather than standard IO; > much as expect does but very simply and of very limited > scope. > > This script works fine on AIX but not on SunOS or Linux. > > I need to know how to get the name of the slave side after > opening the control side (/dev/ptc on AIX and /dev/ptmx on > the others). On AIX ttyname does this for me but it returns > "Inappropriate ioctl for device" elsewhere. > > I don't mean to take up time and space on this list but I have been > looking unsuccessfully for a suitable mailing list more suited to > my problem. > > Thank you for any pointers. > > Best regards, > Carlyle > -- > > Informationen (einschließlich Pflichtangaben) zu einzelnen, innerhalb der EU tätigen Gesellschaften und Zweigniederlassungen des Konzerns Deutsche Bank finden Sie unter http://www.db.com/de/content/pflichtangaben.htm. Diese E-Mail enthält vertrauliche und/ oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser E-Mail ist nicht gestattet. > > Please refer to http://www.db.com/en/content/eu_disclosures.htm for information (including mandatory corporate particulars) on selected Deutsche Bank branches and group companies registered or incorporated in the European Union. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |
From: Carlyle S. <car...@db...> - 2008-02-06 14:51:19
|
Thank you for picking this up. No, I can't install IO::Tty. I would have to justify rolling out non-standard packages on many hundreds of servers. But if I can't get this to fly, I may look at PAR. I only need the slave side (pts) name. I'm sure it must be something simple. The rest works fine. Here is the relevant code: #!/usr/bin/perl -w use strict; use Fcntl; # Needed for O_RDWR and O_NOCTTY flags to sysopen use POSIX qw/setsid ttyname/; use POSIX ":sys_wait_h"; # # Set up my variables and read the command line parameters. # # Open the control side and set non blocking sysopen( PTC, "/dev/ptc", O_RDWR | O_NOCTTY ) or die "Can't open a pseudo-terminal. $!"; $s = select(PTC); $| = 1; select($s); # Get the name of the slave side $ptyname = ttyname(fileno(PTC)) or die "Cannot get slave name: $?, $!\n"; $pid = fork; if ($pid < 0) { die "Can't fork: $1\n"; } if( $pid == 0 ) { # I'm the son ; exec the program... # Break away from the old controling terminal. setsid() or die "Can't setsid: $!\n"; # Open the slave side of the new one and set non-blocking IO sysopen( PTS, $ptyname, O_RDWR ) or die "Can't open a pseudo-terminal (child). $!"; $s = select(PTS); $| = 1; select($s); close STDIN; close STDOUT; close STDERR; open(STDIN,"<&PTS"); open(STDOUT,">&PTS"); open(STDERR,">&STDOUT"); $| = 1; exec $prog-needing-tty; } $| = 1; while( sysread(PTC, $_, 1) ) { print "$_"; $buf = $buf . $_; # # Check for specific string from child # and send the correct responses. # if( ($kid = waitpid(-1, WNOHANG)) > 0 ) { last; } } # Cleanup and exit Regards, Carlyle. Roland Giersig <rgi...@cp...> wrote on 06.02.2008 14:47:49: > Can you post the relevant parts of the script? > > PTY-handling is hard, that's why IO::Tty is doing it in C. And you have > no way of installing IO::Tty locally? If you worry about distribution, > have a look at PAR, the Perl Archiver, on CPAN which lets you package > required modules, even binary ones, with your script. > > Servus, Roland > > Carlyle Sutphen wrote: > > Hello, > > > > I am a system administrator in a large corporation which > > has not included Expect.pm and its siblings IO::Tty and IO::Stty > > in the packaging. > > > > I have written a perl script which creates a terminal for a child > > process which uses the terminal rather than standard IO; > > much as expect does but very simply and of very limited > > scope. > > > > This script works fine on AIX but not on SunOS or Linux. > > > > I need to know how to get the name of the slave side after > > opening the control side (/dev/ptc on AIX and /dev/ptmx on > > the others). On AIX ttyname does this for me but it returns > > "Inappropriate ioctl for device" elsewhere. > > > > I don't mean to take up time and space on this list but I have been > > looking unsuccessfully for a suitable mailing list more suited to > > my problem. > > > > Thank you for any pointers. > > > > Best regards, > > Carlyle > > -- > > > > Informationen (einschließlich Pflichtangaben) zu einzelnen, > innerhalb der EU tätigen Gesellschaften und Zweigniederlassungen des > Konzerns Deutsche Bank finden Sie unter http://www.db. > com/de/content/pflichtangaben.htm. Diese E-Mail enthält vertrauliche > und/ oder rechtlich geschützte Informationen. Wenn Sie nicht der > richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, > informieren Sie bitte sofort den Absender und vernichten Sie diese > E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe > dieser E-Mail ist nicht gestattet. > > > > Please refer to http://www.db.com/en/content/eu_disclosures.htm > for information (including mandatory corporate particulars) on > selected Deutsche Bank branches and group companies registered or > incorporated in the European Union. This e-mail may contain > confidential and/or privileged information. If you are not the > intended recipient (or have received this e-mail in error) please > notify the sender immediately and delete this e-mail. Any > unauthorized copying, disclosure or distribution of the material in > this e-mail is strictly forbidden. > > > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by: Microsoft > > Defy all challenges. Microsoft(R) Visual Studio 2008. > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > > _______________________________________________ > > Expectperl-discuss mailing list > > Exp...@li... > > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > -- Informationen (einschließlich Pflichtangaben) zu einzelnen, innerhalb der EU tätigen Gesellschaften und Zweigniederlassungen des Konzerns Deutsche Bank finden Sie unter http://www.db.com/de/content/pflichtangaben.htm. Diese E-Mail enthält vertrauliche und/ oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser E-Mail ist nicht gestattet. Please refer to http://www.db.com/en/content/eu_disclosures.htm for information (including mandatory corporate particulars) on selected Deutsche Bank branches and group companies registered or incorporated in the European Union. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. |
From: Roland G. <rgi...@cp...> - 2008-02-06 15:56:51
|
Carlyle Sutphen wrote: > Thank you for picking this up. > > No, I can't install IO::Tty. I would have to justify rolling out non-standard packages on many > hundreds of servers. Comparing "rolling out a self-written custom script that probably doesn't has an automatic testsuite" to "installing a proven-in-use module" I fail to see the problem... :-) (don't flame me, I know, company policies... *sigh*) > But if I can't get this to fly, I may look at PAR. What I meant was installing the module in a private lib-dir. And yes, then you can package this up with PAR. > I only need the slave side (pts) name. I'm sure it must be something simple. The rest > works fine. No, I don't think it can be done with pure perl. In C you have ptsname() for that purpose, but as it is not POSIX there is no standard perl binding to that that I am aware of (other than in IO::Tty). Generally speaking, pty handling is a black magic and VERY system-dependent. But come to think of, I have a nifty work-around! Use "ssh -t localhost cmd" to spawn the command with a terminal as stdin/out and interact with that via open2() or open3(). How does that sound? Hope this helps, Roland > Here is the relevant code: > > #!/usr/bin/perl -w > use strict; > use Fcntl; # Needed for O_RDWR and O_NOCTTY flags to sysopen > use POSIX qw/setsid ttyname/; > use POSIX ":sys_wait_h"; > # > # Set up my variables and read the command line parameters. > # > # Open the control side and set non blocking > sysopen( PTC, "/dev/ptc", O_RDWR | O_NOCTTY ) or die "Can't open a pseudo-terminal. $!"; > $s = select(PTC); $| = 1; select($s); > # Get the name of the slave side That won't work, you need ptsname() here. That this works in AIX is... well, I can't say non-standard, because there is no standard... :-) > $ptyname = ttyname(fileno(PTC)) or die "Cannot get slave name: $?, $!\n"; > $pid = fork; > if ($pid < 0) { > die "Can't fork: $1\n"; > } > if( $pid == 0 ) { # I'm the son ; exec the program... > # Break away from the old controling terminal. > setsid() or die "Can't setsid: $!\n"; > # Open the slave side of the new one and set non-blocking IO > sysopen( PTS, $ptyname, O_RDWR ) or die "Can't open a pseudo-terminal (child). $!"; > $s = select(PTS); $| = 1; select($s); > close STDIN; > close STDOUT; > close STDERR; > open(STDIN,"<&PTS"); > open(STDOUT,">&PTS"); > open(STDERR,">&STDOUT"); > $| = 1; > exec $prog-needing-tty; > } > $| = 1; > while( sysread(PTC, $_, 1) ) { > print "$_"; > $buf = $buf . $_; > # > # Check for specific string from child > # and send the correct responses. > # > if( ($kid = waitpid(-1, WNOHANG)) > 0 ) { > last; > } > } > # Cleanup and exit > > > Regards, > Carlyle. > > Roland Giersig <rgi...@cp...> wrote on 06.02.2008 14:47:49: > >> Can you post the relevant parts of the script? >> >> PTY-handling is hard, that's why IO::Tty is doing it in C. And you have >> no way of installing IO::Tty locally? If you worry about distribution, >> have a look at PAR, the Perl Archiver, on CPAN which lets you package >> required modules, even binary ones, with your script. >> >> Servus, Roland >> >> Carlyle Sutphen wrote: >>> Hello, >>> >>> I am a system administrator in a large corporation which >>> has not included Expect.pm and its siblings IO::Tty and IO::Stty >>> in the packaging. >>> >>> I have written a perl script which creates a terminal for a child >>> process which uses the terminal rather than standard IO; >>> much as expect does but very simply and of very limited >>> scope. >>> >>> This script works fine on AIX but not on SunOS or Linux. >>> >>> I need to know how to get the name of the slave side after >>> opening the control side (/dev/ptc on AIX and /dev/ptmx on >>> the others). On AIX ttyname does this for me but it returns >>> "Inappropriate ioctl for device" elsewhere. >>> >>> I don't mean to take up time and space on this list but I have been >>> looking unsuccessfully for a suitable mailing list more suited to >>> my problem. >>> >>> Thank you for any pointers. >>> >>> Best regards, >>> Carlyle >>> -- >>> >>> Informationen (einschließlich Pflichtangaben) zu einzelnen, >> innerhalb der EU tätigen Gesellschaften und Zweigniederlassungen des >> Konzerns Deutsche Bank finden Sie unter http://www.db. >> com/de/content/pflichtangaben.htm. Diese E-Mail enthält vertrauliche >> und/ oder rechtlich geschützte Informationen. Wenn Sie nicht der >> richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, >> informieren Sie bitte sofort den Absender und vernichten Sie diese >> E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe >> dieser E-Mail ist nicht gestattet. >>> Please refer to http://www.db.com/en/content/eu_disclosures.htm >> for information (including mandatory corporate particulars) on >> selected Deutsche Bank branches and group companies registered or >> incorporated in the European Union. This e-mail may contain >> confidential and/or privileged information. If you are not the >> intended recipient (or have received this e-mail in error) please >> notify the sender immediately and delete this e-mail. Any >> unauthorized copying, disclosure or distribution of the material in >> this e-mail is strictly forbidden. >>> >>> ------------------------------------------------------------------------- >>> This SF.net email is sponsored by: Microsoft >>> Defy all challenges. Microsoft(R) Visual Studio 2008. >>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >>> _______________________________________________ >>> Expectperl-discuss mailing list >>> Exp...@li... >>> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >>> > > -- > > Informationen (einschließlich Pflichtangaben) zu einzelnen, innerhalb der EU tätigen Gesellschaften und Zweigniederlassungen des Konzerns Deutsche Bank finden Sie unter http://www.db.com/de/content/pflichtangaben.htm. Diese E-Mail enthält vertrauliche und/ oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser E-Mail ist nicht gestattet. > > Please refer to http://www.db.com/en/content/eu_disclosures.htm for information (including mandatory corporate particulars) on selected Deutsche Bank branches and group companies registered or incorporated in the European Union. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. > > |
From: Carlyle S. <car...@db...> - 2008-02-06 16:46:33
|
I answered all your comments including the mention of ptsname(). Roland Giersig <rgi...@cp...> wrote on 06.02.2008 16:56:30: > Carlyle Sutphen wrote: > > Thank you for picking this up. > > > > No, I can't install IO::Tty. I would have to justify rolling out > non-standard packages on many > > hundreds of servers. > > Comparing "rolling out a self-written custom script that probably > doesn't has an automatic testsuite" to "installing a proven-in-use > module" I fail to see the problem... :-) (don't flame me, I know, > company policies... *sigh*) Yes, we just don't fight global engineering any more :( The testing is not automized, true, but the scripts we roll out generally never get developed any further. The are written to do a simple task and last forever or until an OS upgrade breaks them. > > > But if I can't get this to fly, I may look at PAR. > > What I meant was installing the module in a private lib-dir. And yes, > then you can package this up with PAR. I understood that. Sounds good. I will certainly look into that at least for future use. > > > I only need the slave side (pts) name. I'm sure it must be > something simple. The rest > > works fine. > > No, I don't think it can be done with pure perl. In C you have ptsname() > for that purpose, but as it is not POSIX there is no standard perl > binding to that that I am aware of (other than in IO::Tty). > > Generally speaking, pty handling is a black magic and VERY system-dependent. > > But come to think of, I have a nifty work-around! Use "ssh -t localhost > cmd" to spawn the command with a terminal as stdin/out and interact with > that via open2() or open3(). How does that sound? I'll try that but it sounds too simple, it can't work ;-P > > Hope this helps, > > Roland > > > Here is the relevant code: > > > > #!/usr/bin/perl -w > > use strict; > > use Fcntl; # Needed for O_RDWR and O_NOCTTY flags to sysopen > > use POSIX qw/setsid ttyname/; > > use POSIX ":sys_wait_h"; > > # > > # Set up my variables and read the command line parameters. > > # > > # Open the control side and set non blocking > > sysopen( PTC, "/dev/ptc", O_RDWR | O_NOCTTY ) or die "Can't open a > pseudo-terminal. $!"; > > $s = select(PTC); $| = 1; select($s); > > # Get the name of the slave side > > That won't work, you need ptsname() here. That this works in AIX is... > well, I can't say non-standard, because there is no standard... :-) I saw that. I also found something else: #################### sub ptsname { my $fd = shift; my $name = '/dev/pts/'; my $pty; unless( ioctl( \*$fd, &TIOCGPTN, $pty ) ) { unless( ioctl( \*$fd, &DEF_TIOCGPTN, $pty ) ) { ioctl( \*$fd, &TIOCGPTN|0x00040000, $pty ); } } $pty = ord(unpack("A", $pty)); return $name.$pty; } #################### For my purpose I would drop the GLOB ref. But how do I get the defines from unistd.h into variables my perl script. Then I could replace the function refs. > > > $ptyname = ttyname(fileno(PTC)) or die "Cannot get slave name: $?, $!\n"; > > $pid = fork; > > if ($pid < 0) { > > die "Can't fork: $1\n"; > > } > > if( $pid == 0 ) { # I'm the son ; exec the program... > > # Break away from the old controling terminal. > > setsid() or die "Can't setsid: $!\n"; > > # Open the slave side of the new one and set non-blocking IO > > sysopen( PTS, $ptyname, O_RDWR ) or die "Can't open a pseudo- > terminal (child). $!"; > > $s = select(PTS); $| = 1; select($s); > > close STDIN; > > close STDOUT; > > close STDERR; > > open(STDIN,"<&PTS"); > > open(STDOUT,">&PTS"); > > open(STDERR,">&STDOUT"); > > $| = 1; > > exec $prog-needing-tty; > > } > > $| = 1; > > while( sysread(PTC, $_, 1) ) { > > print "$_"; > > $buf = $buf . $_; > > # > > # Check for specific string from child > > # and send the correct responses. > > # > > if( ($kid = waitpid(-1, WNOHANG)) > 0 ) { > > last; > > } > > } > > # Cleanup and exit > > > > > > Regards, > > Carlyle. > > > > Roland Giersig <rgi...@cp...> wrote on 06.02.2008 14:47:49: > > > >> Can you post the relevant parts of the script? > >> > >> PTY-handling is hard, that's why IO::Tty is doing it in C. And you have > >> no way of installing IO::Tty locally? If you worry about distribution, > >> have a look at PAR, the Perl Archiver, on CPAN which lets you package > >> required modules, even binary ones, with your script. > >> > >> Servus, Roland > >> > >> Carlyle Sutphen wrote: > >>> Hello, > >>> > >>> I am a system administrator in a large corporation which > >>> has not included Expect.pm and its siblings IO::Tty and IO::Stty > >>> in the packaging. > >>> > >>> I have written a perl script which creates a terminal for a child > >>> process which uses the terminal rather than standard IO; > >>> much as expect does but very simply and of very limited > >>> scope. > >>> > >>> This script works fine on AIX but not on SunOS or Linux. > >>> > >>> I need to know how to get the name of the slave side after > >>> opening the control side (/dev/ptc on AIX and /dev/ptmx on > >>> the others). On AIX ttyname does this for me but it returns > >>> "Inappropriate ioctl for device" elsewhere. > >>> > >>> I don't mean to take up time and space on this list but I have been > >>> looking unsuccessfully for a suitable mailing list more suited to > >>> my problem. > >>> > >>> Thank you for any pointers. > >>> > >>> Best regards, > >>> Carlyle -- Informationen (einschließlich Pflichtangaben) zu einzelnen, innerhalb der EU tätigen Gesellschaften und Zweigniederlassungen des Konzerns Deutsche Bank finden Sie unter http://www.db.com/de/content/pflichtangaben.htm. Diese E-Mail enthält vertrauliche und/ oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser E-Mail ist nicht gestattet. Please refer to http://www.db.com/en/content/eu_disclosures.htm for information (including mandatory corporate particulars) on selected Deutsche Bank branches and group companies registered or incorporated in the European Union. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. |
From: Roland G. <rgi...@cp...> - 2008-02-07 11:38:39
|
>> But come to think of, I have a nifty work-around! Use "ssh -t localhost >> cmd" to spawn the command with a terminal as stdin/out and interact with >> that via open2() or open3(). How does that sound? > > I'll try that but it sounds too simple, it can't work ;-P Yes it will work. :-P And probably save you a lot of coding... > unless( ioctl( \*$fd, &TIOCGPTN, $pty ) ) { > unless( ioctl( \*$fd, &DEF_TIOCGPTN, $pty ) ) { > ioctl( \*$fd, &TIOCGPTN|0x00040000, $pty ); > > For my purpose I would drop the GLOB ref. But how do I get the defines from > unistd.h into variables my perl script. Then I could replace the function refs. Easy. Just look up the values for TIOCGPTN etc. in the .h files and put them hard-coded into you program, eg ioctl($fd, 0x47110815, $pty); But I don't recommend that, use ssh instead, because that's more reliable and portable... Hope this helps, Roland |