So I have a program with a UI that I am writing. I have four button in my UI. Two of which call system commands, push the output to a file and finally display the text in the file in a scrolledwindow. The first button works flawlessly. The second works as far as calling the system command and pushes the output to a file but fails to display the text from the file in the scrolled window.

use strict; use warnings; use diagnostics; use Tk; use Data::Dumper; require Tk::Pane; my $mw = MainWindow->new( ); $mw->geometry("300x300"); $mw->title("Dummy"); $mw->protocol( WM_DELETE_WINDOW => \&ask, ); my $SixPairButton = $mw->Button( -text => "START", -command => \&sixpair, )->pack( -side => "top", -anchor => "nw", ); my $SixAdButton = $mw->Button( -text => "PAIR", -command => \&sixad, )->pack( -side => "top", -anchor => "nw", ); my $ClearButton = $mw->Button( -text => "CLEAR", -command => \&clear, )->pack( -side => "top", -anchor => "nw", ); my $QuitButton = $mw->Button( -text => "QUIT", -command => \&stopad, )->pack( -side => "top", -anchor => "nw", ); my $Pane = $mw->Scrolled( 'Text', Name => 'Display', -scrollbars => 'e', -relief => "sunken", -background => "WHITE" )->pack( -side => 'bottom', -fill => 'both', -padx => '5', ); my $Count = 0; sub warning { my $Tlw = $mw->Toplevel; $Tlw->title('Warning'); my $Label = $Tlw->Label( -text => 'Please connect controller before pa +iring.' )->pack( -side => 'top', -pady => '15' ); $Tlw->Button( -text => "OK", -command => sub { $Tlw->withdraw }, )->pack( -side => 'bottom +', -anchor => 'se', -padx => '5', -pady => '5' ); }; my @file1; my $OutFile1; sub sixpair { open $OutFile1, "+>", "tmp1", or die "Can't open file: $!"; my @sixpair = qw(sixpair >tmp1); my $OutPut1 = system( "@sixpair" ); @file1 = <$OutFile1>; for my $i ( @file1 ) { $Pane->insert("end", $i); } $Count = 1; close($OutFile1); return }; sub sixad { for my $t ( @file1 ) { if( $t =~ m/No controller found on USB busses./ ) { &warning; return } } if ( $Count gt 0 ) { open my $OutFile2, "+>", "tmp2", or die "Can't open file: $!"; my @sixad = qw(sixad --start 2>tmp2); my $OutPut2 = system( "@sixad" ); my @file2 = < $OutFile2 >; for my $n ( @file2 ) { print "$n"; $Pane->insert("end", $n); return; } close($OutFile2); return; } else { &warning; return; } }; sub ask { my $Tlw = $mw->Toplevel; $Tlw->title('Prompt'); my $Label = $Tlw->Label( -text => 'Are you sure?' )->pack( -side => 't +op', -pady => '15' ); $Tlw->Button( -text => "Quit", -command => \&stopad, )->pack( -side => 'left', -anchor => 'sw', -padx => '5', -pady => '5', ); $Tlw->Button( -text => "Cancel", -command => sub { $Tlw->withdraw }, )->pack( -side => 'right' +, -anchor => 'se', -padx => '5', -pady => '5' ); }; sub clear { $Pane->delete('0.1', 'end'); }; sub stopad { my @stopad = qw/sixad --stop/; system(@stopad); exit 0; }; sub counter { $Count = '1'; }; MainLoop; =pod ## If your Bluetooth disappears or stops working run hciconfig hci0 up hciconfig -a if [[ $(hciconfig -a | grep -o "DOWN") ]]; then echo -e "\nBluetooth is off.\nTurning it on now.\n"; hciconfig set up; else echo -e "\nBluetooth is already on.\n"; fi =cut


How can I fix this? Thank you!

In reply to text from 2nd file not displaying in scrolledwindow by amboxer21

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.