Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

IO::Pty::Easy from a non-interactive shell

by dfdumont (Initiate)
on Mar 13, 2013 at 20:54 UTC ( [id://1023294]=perlquestion: print w/replies, xml ) Need Help??

dfdumont has asked for the wisdom of the Perl Monks concerning the following question:

I see at least one other has had issues with xinetd. It also exhibits the same condition for me from cron, from an at job, even from a script that I've nohup'd and then logged out of the session. Apparently a controlling vty is needed.

The code segment itself looks like this:

if( $options{protocol} eq 'ssh' ) { unless( defined $options{userid} ) { die "userid is a required parameter when using ssh\n"; } if( $options{login} and not defined $options{passwd} ) { die "passwd is a required parameter for ssh if login is true\n"; } @args = ( '/usr/bin/' . $options{protocol}, '-l', $options{userid} +, '-p', $options{port}, '-q', '-o','StrictHostKeyChecking=no',$option +s{target} ); } elsif( $options{protocol} eq 'telnet' ) { @args = ( '/usr/bin/' . $options{protocol}, $options{target}, $opt +ions{port} ); if( $options{login} ) { unless( defined $options{userid} and defined $options{passwd} ) +{ die "userid and passwd are both required parameters for telnet + if login is true\n"; } } } else { die "Unknown protocol specified: $options{protocol}\n"; } if( $options{logging} ) { unless( defined $options{logfile} ) { $options{logfile} = "$options{target}.log"; } open( $options{fh}, ">", $options{logfile} ) || die "Can't open fi +le $options{logfile}: $!\n"; } # ==================================================================== +========= # Spawn the child process to contact the target device # ==================================================================== +========= $options{pty} = IO::Pty::Easy->new; $options{pty}->spawn(@args) or die "Unable to spawn child process: $ +!\n";

at which point I unuversally get the "Unable to spawn child process" with no error number.

And yes, it works fine if I fire off the script from an interactive shell. That is the only way it does work.

What am I missing? I can't believe anything in Perl would REQUIRE an interactive shell.

(Oh and its running on CentOS 6.3 - so Linux not Windows)

Please advise.

Replies are listed 'Best First'.
Re: IO::Pty::Easy from a non-interactive shell
by Illuminatus (Curate) on Mar 14, 2013 at 19:14 UTC
    Sorry for the delayed reply. I only had time to look at this now. *caveat* I haven't had to do pty-related coding in a while, so my knowledge of the 'tricks' is hazy.

    I looked over the code in IO::Pty::Easy and IO::Pty, and it looks like it always handles the case where there is no tty associated with the process. What I would probably do is run the program using strace (ie, have xinetd call a shell script which runs "strace <perl-script> >& /tmp/data.out" And look for unexpected system call failures.

    fnord

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1023294]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-24 04:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found