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

Dear Masters,

I usually runs backtick to output it's value into an array. Since I have a problem with TTY, now I would like to do the very same task under IPC::Run's 'PTY' command.

But I'm not sure how to do it? Can anybody suggest how to go about it?
#!/usr/bin/perl -w use strict; use Data::Dumper; use CGI qw/:standard :html3/; use CGI::Carp qw( fatalsToBrowser ); use IPC::Run qw( run ); print header(); my $otype = 'AG'; # Else 'SC' # The reason why I wan't to use PTY is because under backticks # param with 'AG' doesn't work, although 'SC' works # See related links for original problem. my $seq_file = '../input_files/input.txt'; # Backtick output is kept into an array my @output = `src/some_binary.out -f $seq_file -O $otype `; chomp @output; print Dumper \@output; # how can I achieve the similar result with above backtick # (i.e. output the stdout to array) # with IPC::Run here... my @cmd = ( "src/some_binary.out", "-f",$seq_file, "-O", $otype); # I'm stuck here. Don't know how # to construct the command correctly... run \@cmd, '<pty<', \$in, '>pty>', \@output ;


---
neversaint and everlastingly indebted.......
  • Comment on Backticks equivalent of outputting the STDOUT to an array to IPC::Run's PTY
  • Download Code

Replies are listed 'Best First'.
Re: Backticks equivalent of outputting the STDOUT to an array to IPC::Run's PTY
by shmem (Chancellor) on Jul 24, 2006 at 06:01 UTC
    Dear neversaint,

    From the discussion in your related thread it is not clear at all that you really are facing a problem involving ptys. Maybe you should make sure first that this is the case?

    Otherwise, this follow-up exposes an XY Problem. You were given some hints, and questions whose answers will help us to help you track down the problem. What about those?

    # I'm stuck here. Don't know how # to construct the command correctly... run \@cmd, '<pty<', \$in, '>pty>', \@output ;

    According to the documentation of IPC::Run

    # Redirecting using psuedo-terminals instad of pipes. run \@cat, '<pty<', \$in, '>pty>', \$out_and_err ;
    STDOUT and STDERR are captured into a SCALAR reference. Try that, and split the content into your array as convenient.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}