Thread Windows 7 Konsole nicht einfach beenden
(18 answers)
Opened by Mike at 2011-08-03 09:32
Hier deinen Code nochmal formatiert und mit ein paar spontanen Änderungen:
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 #!C:\Perl\bin\perl ##=============== Fehlermeldungen/DEBUG ===============## use warnings; use strict; use diagnostics; ##=============== END ===============## ##=============== INI-Benötigte Befehle ===============## use Config::IniFiles; my $config = Config::IniFiles->new( -file => "tsreader.ini" ); my $port = $config->val( "port", "tsport" ); my $ip = $config->val( "ip", "tsip" ); my $pfad1 = $config->val( "pfad", "phtml1" ); my $pfad2 = $config->val( "pfad", "phtml2" ); my $freq1 = $config->val( "frequenz", "freq1" ); my $freq2 = $config->val( "frequenz", "freq2" ); ##=============== END ===============## ##=============== Variablen Declarieren ===============## my $t = ''; my $function = "Funktion:"; my $doit = ''; my $dont_send = ''; my $chart = ''; my $program_number = ''; my $multicast_address = ''; my $multicast_port = ''; my @line = ''; ##=============== END ===============## ##=============== Verbindung/Controll TSreader ===============## use Telnet (); ##=============== Connect to TSReader ===============## $t = new Net::Telnet( Timeout => 1, Port => $port ); eval { $t->open($ip); }; if($@){ # error handling.... } my $x = 100; for ( my $i = 1 ; $i < $x ; ) { ##=============== Display TSReader sent us===============## @line = $t->getline(); print "TSReader connected.\nResponse: @line\n"; ##=============== Display functions ===============## print "Functions supported are:\n"; print " 1 - print programs in mux\n"; print " 2 - display graph\n"; print " 3 - switch to a multicast UDP mux\n"; print " 4 - play channel via VLC\n"; print " 5 - export to HTML\n"; print " 6 - Exit\n"; print "Function? "; $function = <STDIN>; chomp $function; if ( $function == 1 ) { #Get and print a list of programs $t->print("PROGRAM"); print "These programs are defined:\n"; $doit = 1; while ( $doit eq 1 ) { eval { @line = $t->getline( Timeout => 1 ); }; if ($@) { $doit = 0; } else { print @line; } } } elsif ( $function == 2 ) { #Draw a graph $dont_send = 0; print "Available graphs are:\n"; print " 0 - close any existing graph\n"; print " 1 - Active PIDs by rate\n"; print " 2 - Active PIDs by PID\n"; print " 3 - PID usage 2D pie\n"; print " 4 - PID usage 3D pie\n"; print " 5 - Mux usage stacked area\n"; print " 6 - Mux usage line\n"; print " 7 - Video rate area\n"; print " 8 - Video rate line\n"; print " 9 - Program usage\n"; print " 10 - Video composition\n"; print "Which chart? "; $chart = <STDIN>; chomp $chart; if ( $chart == 10 ) { print "Program number? "; $program_number = <STDIN>; chop $program_number; $t->print("PROGRAM $program_number"); @line = $t->getline( Timeout => 1 ); if ( @line = "~ /502/" ) { print("?Invalid program number!\n"); $dont_send = 1; } } if ( $dont_send == 0 ) { $t->print("GRAPH $chart"); @line = $t->getline( Timeout => 1 ); } } elsif ( $function == 3 ) { #Switch to the multicast source and restart TSReader print "Multicast address to listen to? "; $multicast_address = <STDIN>; chomp $multicast_address; print "UDP port to listen to? "; $multicast_port = <STDIN>; chomp $multicast_port; $t->print("SOURCE TSReader_UDPMulticast.dll"); @line = $t->getline( Timeout => 1 ); print "Response to SOURCE: @line"; $t->print("TUNE $multicast_address $multicast_port"); @line = $t->getline( Timeout => 1 ); print "Response to TUNE: line"; } elsif ( $function == 4 ) { $dont_send = 0; print "Program number? "; $program_number = <STDIN>; chomp $program_number; $t->print("PROGRAM $program_number"); @line = $t->getline( Timeout => 1 ); if ( @line = "~ /502/" ) { print("?Invalid program number!\n"); $dont_send = 1; } if ( $dont_send eq 0 ) { $t->print("PLAY VLC1"); @line = $t->getline( Timeout => 1 ); print "Response to PLAY: @line"; } } elsif ( $function == 5 ) { $dont_send = 0; $t->print("TUNE $freq1"); print "Changed Tuner 1\n"; sleep(10); $t->print("EXPORT HTML $pfad1"); sleep(3); $dont_send = 0; $t->print("TUNE $freq2"); print "Changed Tuner2\n"; sleep(10); $t->print("EXPORT HTML $pfad2"); print "HTML-Seiten wurde erfolgreich Exportiert\n\n"; } } #all done $dont_send = 0; print "Beenden"; $function = <STDIN>; if ( $function == 6 ) { $t->print(''); } So ist es lesbarer. Beim Vergleich von Zahlen nutzt man "==" bei Strings "eq" aber dann als Code (perl): (dl
)
if($foo eq "bar"){ Gruß Kristian EDIT: da war noch ein eq... EDIT2: Wer erklärt mir denn diese Zeile? Code (perl): (dl
)
if ( @line = "~ /502/" ) { Wenn die Erklärung auf Code (perl): (dl
)
if(1){ raus läuft brauch ich das nicht Last edited: 2011-08-03 20:42:24 +0200 (CEST) |