| 1 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =encoding utf8 | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | Quiq::Shell - Führe Shell-Kommandos aus | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 BASE CLASS | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | L<Quiq::Hash> | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =cut | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | package Quiq::Shell; | ||||||||||||||||||||||||||||
| 18 | 270 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 19 | 270 | ▶ | $INC{'Quiq/Shell.pm'} ||= __FILE__; | ||||||||||||||||||||||||||
|
Condition50%1/2
$INC{"Quiq/Shell.pm"} ||= __FILE__
MC/DC0%0/1
$INC{"Quiq/Shell.pm"} ||= __FILE__
$INC{"Quiq/Shell.pm"}
Truth table50%1/2
A
A= $INC{"Quiq/Shell.pm"}
| |||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | 270 | ▶ | use base qw/Quiq::Hash/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 270 | ▶ | use v5.10; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 270 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 270 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 270 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 270 | our $VERSION = '1.240'; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 270 | ▶ | use Time::HiRes (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 270 | ▶ | use Quiq::Duration; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 270 | ▶ | use Quiq::AnsiColor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 270 | ▶ | use Quiq::Option; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 270 | ▶ | use Quiq::Path; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 270 | ▶ | use Quiq::Converter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 270 | ▶ | use Quiq::Exit; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 270 | ▶ | use Quiq::Process; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head1 METHODS | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =head2 Konstruktor/Destruktor | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =head3 new() - Konstruktor | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =head4 Synopsis | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | $sh = $class->new(@opt); | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =head4 Options | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =over 4 | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =item cmdPrefix => $str (Default: '') | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | Zeichenkette, der jeder Kommandozeile im Log vorangestellt wird. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =item cmdAnsiColor => $str (Default: '') | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | ANSI Escape-Sequenz, die auf eine Kommandozeile angewendet wird, | ||||||||||||||||||||||||||||
| 62 | z.B. 'bold red'. | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =item dryRun => $bool (Default: 0) | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | Führe Kommandos nicht aus, sondern logge sie nur (impliziert log=>1). | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =item log => $bool (Default: 0) | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | Log Commands to STDOUT. | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =item logDest => $fd (Default: *STDOUT) | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | Datei-Deskriptor, auf den die Logmeldungen geschrieben werden. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =item logRewrite => $sub (Default: undef) | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | Callback-Methode, die die Kommandozeile vor dem Logging umschreibt. | ||||||||||||||||||||||||||||
| 79 | Dies ist nützlich, falls die Kommandozeile ein Passwort enthält, | ||||||||||||||||||||||||||||
| 80 | das im Log ausgeixt werden soll. Die Methode wird auf dem | ||||||||||||||||||||||||||||
| 81 | Shell-Objekt gerufen: | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | logRewrite => sub { | ||||||||||||||||||||||||||||
| 84 | my ($sh,$cmd) = @_; | ||||||||||||||||||||||||||||
| 85 | # $cmd umschreiben | ||||||||||||||||||||||||||||
| 86 | return $cmd; | ||||||||||||||||||||||||||||
| 87 | }, | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =item msgPrefix => $str (Default: '') | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | Zeichenkette, die jeder Meldung im Log vorangestellt wird. | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =item quiet => $bool | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | Unterdrücke stdout und stderr. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =item sloppy => $bool | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | Ignoriere den Exitcode. | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =item time => $bool (Default: 0) | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | Gib nach jedem Kommando die Zeit aus, die es benötigt hat. | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =item timePrefix => $str (Default: '') | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | Zeichenkette, die jeder Zeitausgabe vorangestellt wird. | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =item timeSummary => $bool (Default: 0) | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | Gib zum Schluss bei der Destrukturierung des Objekts | ||||||||||||||||||||||||||||
| 112 | die Gesamtausführungszeit aus. | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =back | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =head4 Description | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | Instantiiere ein Shell-Objekt, und liefere eine Referenz auf dieses | ||||||||||||||||||||||||||||
| 119 | Objekt zurück. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =cut | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 24 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | 24 | my $class = shift; | |||||||||||||||||||||||||||
| 127 | # @_: @keyVal | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 24 | my $self = $class->SUPER::new( | |||||||||||||||||||||||||||
| 130 | cmdPrefix => '', | ||||||||||||||||||||||||||||
| 131 | cmdAnsiColor => undef, | ||||||||||||||||||||||||||||
| 132 | dryRun => 0, | ||||||||||||||||||||||||||||
| 133 | dirStack => [], | ||||||||||||||||||||||||||||
| 134 | log => 0, | ||||||||||||||||||||||||||||
| 135 | logDest => *STDOUT, | ||||||||||||||||||||||||||||
| 136 | logRewrite => undef, | ||||||||||||||||||||||||||||
| 137 | msgPrefix => '', | ||||||||||||||||||||||||||||
| 138 | quiet => 0, | ||||||||||||||||||||||||||||
| 139 | sloppy => 0, | ||||||||||||||||||||||||||||
| 140 | time => 0, | ||||||||||||||||||||||||||||
| 141 | timePrefix => '', | ||||||||||||||||||||||||||||
| 142 | timeSummary => 0, | ||||||||||||||||||||||||||||
| 143 | t0 => Time::HiRes::gettimeofday, | ||||||||||||||||||||||||||||
| 144 | ); | ||||||||||||||||||||||||||||
| 145 | 24 | $self->set(@_); | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 24 | return $self; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | =head3 DESTROY() - Destruktor | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =head4 Synopsis | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | $sh->%METH; | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =head4 Description | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | Wenn timeSummary gesetzt ist, wird im Zuge der Destruktuierung | ||||||||||||||||||||||||||||
| 161 | die Gesamtausführungszeit für alle Kommandos, die über das | ||||||||||||||||||||||||||||
| 162 | Shell-Objekt ausgeführt wurden, ausgegeben. | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =cut | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 23 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=3 SCAR=17.8
| |||||||||||||||||||||||||||||
| 169 | 23 | my $self = shift; | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 23 | ▶ | if ($self->{'timeSummary'} && $self->{'log'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"timeSummary"} and $self->{"log"}
MC/DC0%0/2
$self->{"timeSummary"} and $self->{"log"}
$self->{"timeSummary"}
$self->{"log"}
Truth table33%1/3
A and B
A= $self->{"timeSummary"}B= $self->{"log"}
| |||||||||||||||||||||||||||||
| 172 | 0 | (my $prog = $0) =~ s|.*/||; | |||||||||||||||||||||||||||
| 173 | 0 | my $fd = $self->{'logDest'}; | |||||||||||||||||||||||||||
| 174 | 0 | my $pre = $self->{'msgPrefix'}; | |||||||||||||||||||||||||||
| 175 | 0 | my $t = Time::HiRes::gettimeofday-$self->{'t0'}; | |||||||||||||||||||||||||||
| 176 | 0 | my $duration = Quiq::Duration->new($t)->asString(2); | |||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | # printf $fd "%s%s: %s\n",$pre,$prog,$duration; | ||||||||||||||||||||||||||||
| 179 | 0 | my $esc = $self->{'cmdAnsiColor'}; | |||||||||||||||||||||||||||
| 180 | 0 | my $a = Quiq::AnsiColor->new($esc); | |||||||||||||||||||||||||||
| 181 | # printf $fd $a->strLn($esc,sprintf "%s%s: %s",$pre,$prog,$duration); | ||||||||||||||||||||||||||||
| 182 | 0 | printf $fd $a->strLn($esc,sprintf "%s%s",$pre,$duration); | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 23 | return; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | =head2 Kommando ausführen | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | =head3 exec() - Führe Kommando aus | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | =head4 Synopsis | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | $str|@arr = $this->exec($cmd,@opt); | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | =head4 Options | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | =over 4 | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | =item -capture => $channels (Default: keiner) | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | Liefere die die Programmausgabe auf dem Kanal bzw. den Kanälen | ||||||||||||||||||||||||||||
| 205 | $channels zurück. Mögliche Werte für $channels: | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | =over 4 | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | =item 'stdout' | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | Liefere Ausgabe auf stdout, unterdrücke stderr. | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | =item 'stderr' | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | Liefere Ausgabe auf stderr, unterdrücke stdout. | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | =item 'stdout+stderr' | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | Liefere Ausgabe auf stdout und stderr zusammen. | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | =item 'stdout,stderr' | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | Liefere Ausgabe auf stdout und stderr getrennt. | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | =back | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | Für Beispiele siehe Abschnitt ""exec/Examples"". | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | =item -log => $bool (Default: 0) | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | Logge das Kommando auf STDOUT. | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | =item -outputTo => $name | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | Schreibe jegliche Ausgabe von $cmd auf stdout und stderr nach | ||||||||||||||||||||||||||||
| 236 | $name-NNNN.log. NNNN ist eine laufende Nummer, die mit jedem | ||||||||||||||||||||||||||||
| 237 | Programmaufruf um 1 erhöht wird. Beispiel: | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | perl -MQuiq::Shell -E 'Quiq::Shell->exec("echo hallo",-outputTo=>"echo")' | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | =item -quiet => $bool (Default: 0) | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | Unterdrücke Programmausgabe auf stdout und stderr. | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | =item -sloppy => $bool (Default: 0) | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | Wirf keine Exception, wenn das Programm fehlschlägt, sondern | ||||||||||||||||||||||||||||
| 248 | liefere dessen Exitcode. Ist gleichzeitig die Option -capture angegeben, | ||||||||||||||||||||||||||||
| 249 | hat diese hinsichtlich des Rückgabewerts Priorität. | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | =back | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | =head4 Returns | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | Der Rückgabewert richtet sich nach den Optionen @opt. Ist -capture | ||||||||||||||||||||||||||||
| 256 | definiert, wird die angegebene Programmausgabe geliefert. Ist | ||||||||||||||||||||||||||||
| 257 | -sloppy wahr, wird der Exitcode geliefert. Die Option -capture hat | ||||||||||||||||||||||||||||
| 258 | Priorität gegenüber der Option -sloppy. Sind weder -capture noch | ||||||||||||||||||||||||||||
| 259 | -sloppy angegeben, liefert die Methode keinen Wert. | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | =head4 Description | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | Führe Kommando $cmd aus. Im Falle eines Fehlers löse eine Exception aus. | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | Beginnt das Kommando $cmd mit einem Bindestrich, wird | ||||||||||||||||||||||||||||
| 266 | implizit die Option -sloppy gesetzt. | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | =head4 Examples | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | Unterdrücke Ausgabe auf stdout und stderr: | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | $this->exec($cmd,-quiet=>1); | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | Liefere Ausgabe auf stdout: | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | $stdout = $this->exec($cmd,-capture=>'stdout'); | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | Liefere Ausgabe auf stderr: | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | $stderr = $this->exec($cmd,-capture=>'stderr'); | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | Liefere Ausgabe auf stdout und stderr zusammen: | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | $output = $this->exec($cmd,-capture=>'stdout+stderr'); | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | Liefere Ausgabe auf stdout und stderr getrennt: | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | ($stdout,$stderr) = $this->exec($cmd,-capture=>'stdout,stderr'); | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | Keine Exception, liefere Exitcode: | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | $exitCode = $this->exec($cmd,-sloppy=>1); | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | =cut | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | 21 | ▶ | sub exec { | ||||||||||||||||||||||||||
|
Subroutine
exec: called CC=24 SCAR=40.8
Pod
documented
| |||||||||||||||||||||||||||||
| 299 | 21 | ▶ | my $self = ref $_[0]? shift: shift->new; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 300 | 21 | my $cmd = shift; | |||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | # Optionen | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | 21 | my $capture = undef; | |||||||||||||||||||||||||||
| 305 | 21 | my $log = 0; | |||||||||||||||||||||||||||
| 306 | 21 | my $outputTo = undef; | |||||||||||||||||||||||||||
| 307 | 21 | my $quiet = $self->get('quiet'); | |||||||||||||||||||||||||||
| 308 | 21 | my $sloppy = $self->get('sloppy'); | |||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | 21 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | 1 | Quiq::Option->extract(\@_, | |||||||||||||||||||||||||||
| 312 | -capture => \$capture, | ||||||||||||||||||||||||||||
| 313 | -log => \$log, | ||||||||||||||||||||||||||||
| 314 | -outputTo => \$outputTo, | ||||||||||||||||||||||||||||
| 315 | -quiet => \$quiet, | ||||||||||||||||||||||||||||
| 316 | -sloppy => \$sloppy, | ||||||||||||||||||||||||||||
| 317 | ); | ||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 21 | my $p = Quiq::Path->new; | |||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | # Exception? | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 21 | my $except = 1; # löse Exception aus | |||||||||||||||||||||||||||
| 325 | 21 | ▶ | if ($sloppy || $cmd =~ s/^-//) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$sloppy or $cmd =~ s/^-//
MC/DC50%1/2
$sloppy or $cmd =~ s/^-//
$sloppy
$cmd =~ s/^-//
Truth table66%2/3
A or B
A= $sloppyB= $cmd =~ s/^-//
| |||||||||||||||||||||||||||||
| 326 | 1 | $except = 0; | |||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | # Umleitungen | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 21 | ▶ | if (my $name = $outputTo) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 332 | # Alle Ausgaben in Logdatei schreiben. Mit jedem Lauf wird | ||||||||||||||||||||||||||||
| 333 | # die Nummmer der Logdatei inkrementiert. | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | 0 | my $logFile = $p->nextFile($name,4,'log'); | |||||||||||||||||||||||||||
| 336 | 0 | $cmd = "($cmd) 2>&1 | tee $logFile"; | |||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | 21 | ▶ | if ($quiet) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 340 | 0 | $cmd = "($cmd) >/dev/null 2>&1"; | |||||||||||||||||||||||||||
| 341 | 0 | $capture = undef; | |||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | 21 | my $qx = 0; | |||||||||||||||||||||||||||
| 345 | # FIXME: auf Quiq::TempFile umstellen | ||||||||||||||||||||||||||||
| 346 | 21 | my $stdoutFile = "/tmp/$$.stdout"; | |||||||||||||||||||||||||||
| 347 | 21 | my $stderrFile = "/tmp/$$.stderr"; | |||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | 21 | ▶ | if (!$capture) { | ||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||
| 350 | # keine Abwandlung des Kommandos | ||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | elsif ($capture eq 'stdout') { | ||||||||||||||||||||||||||||
| 353 | 1 | $cmd = "($cmd) 2>/dev/null"; | |||||||||||||||||||||||||||
| 354 | 1 | $qx = 1; | |||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | elsif ($capture eq 'stderr') { | ||||||||||||||||||||||||||||
| 357 | 0 | $cmd = "($cmd) 2>&1 1>/dev/null"; | |||||||||||||||||||||||||||
| 358 | 0 | $qx = 1; | |||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||
| 360 | elsif ($capture eq 'stdout+stderr') { | ||||||||||||||||||||||||||||
| 361 | 0 | $cmd = "($cmd) 2>&1"; | |||||||||||||||||||||||||||
| 362 | 0 | $qx = 1; | |||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||
| 364 | elsif ($capture eq 'stdout,stderr') { | ||||||||||||||||||||||||||||
| 365 | 0 | $cmd = "($cmd) 1>$stdoutFile 2>$stderrFile"; | |||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||
| 367 | else { | ||||||||||||||||||||||||||||
| 368 | 0 | $self->throw( | |||||||||||||||||||||||||||
| 369 | 'CMD-00004: Ungültiger Wert für -capture', | ||||||||||||||||||||||||||||
| 370 | Capture => $capture, | ||||||||||||||||||||||||||||
| 371 | ); | ||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | # Kommando protokollieren | ||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | 21 | my $dryRun = $self->{'dryRun'}; | |||||||||||||||||||||||||||
| 377 | 21 | ▶ | my $doLog = $log || $self->{'log'}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$log || $self->{'log'}
MC/DC0%0/2
$log || $self->{'log'}
$log
$self->{'log'}
Truth table33%1/3
A || B
A= $logB= $self->{'log'}
| |||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | 21 | ▶ | if ($doLog || $dryRun) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$doLog or $dryRun
MC/DC0%0/2
$doLog or $dryRun
$doLog
$dryRun
Truth table33%1/3
A or B
A= $doLogB= $dryRun
| |||||||||||||||||||||||||||||
| 380 | 0 | $self->_logCmd($cmd); | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | # Kommando ausführen | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 21 | my $exit = 0; | |||||||||||||||||||||||||||
| 386 | 21 | my $output; | |||||||||||||||||||||||||||
| 387 | 21 | ▶ | unless ($dryRun) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 388 | 21 | my $t0 = Time::HiRes::gettimeofday; | |||||||||||||||||||||||||||
| 389 | 21 | ▶ | if ($qx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 390 | 1 | $output = qx/$cmd/; | |||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||
| 392 | else { | ||||||||||||||||||||||||||||
| 393 | 20 | system $cmd; | |||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||
| 395 | 21 | $exit = $?; | |||||||||||||||||||||||||||
| 396 | 21 | my $t1 = Time::HiRes::gettimeofday; | |||||||||||||||||||||||||||
| 397 | 21 | ▶ | if ($doLog && $self->{'time'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$doLog and $self->{"time"}
MC/DC0%0/2
$doLog and $self->{"time"}
$doLog
$self->{"time"}
Truth table33%1/3
A and B
A= $doLogB= $self->{"time"}
| |||||||||||||||||||||||||||||
| 398 | 0 | my $fd = $self->{'logDest'}; | |||||||||||||||||||||||||||
| 399 | 0 | printf $fd "%s%s\n",$self->{'timePrefix'}, | |||||||||||||||||||||||||||
| 400 | Quiq::Converter->epochToDuration($t1-$t0,1,3); | ||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||
| 402 | 21 | ▶ | if ($except) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 403 | # geht sonst beim Autoload von checkError() verloren | ||||||||||||||||||||||||||||
| 404 | # my $msg = $!; | ||||||||||||||||||||||||||||
| 405 | # $self->checkError($exit,$msg,$cmd); | ||||||||||||||||||||||||||||
| 406 | 20 | Quiq::Exit->check($?,$cmd); | |||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | # Returnwerte | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | 20 | ▶ | if ($capture) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 413 | 1 | ▶ | if ($capture eq 'stdout,stderr') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 414 | 0 | my $stdout = $p->read($stdoutFile,-delete=>1); | |||||||||||||||||||||||||||
| 415 | 0 | my $stderr = $p->read($stderrFile,-delete=>1); | |||||||||||||||||||||||||||
| 416 | 0 | return ($stdout,$stderr); | |||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | 1 | return $output; | |||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||
| 420 | elsif (!$except) { | ||||||||||||||||||||||||||||
| 421 | 0 | ▶ | if ($exit > 255) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 422 | 0 | $exit = int($exit/256); | |||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||
| 424 | 0 | return $exit; | |||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | 19 | return; | |||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | =head2 Arbeitsverzeichnis wechseln | ||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | =head3 cd() - Wechsele das Arbeitsverzeichnis | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | =head4 Synopsis | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | $sh->cd($dir); | ||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | =head4 Returns | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | Die Methode liefert keinen Wert zurück. | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | =head4 Description | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | Wechsle in Arbeitsverzeichnis $dir. Anmerkung: Diese Änderung gilt | ||||||||||||||||||||||||||||
| 447 | auch für den aufrufenden Prozess, nicht nur für das Shell-Objekt. | ||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | =cut | ||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | 0 | ▶ | sub cd { | ||||||||||||||||||||||||||
|
Subroutine
cd: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 454 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 455 | 0 | my $dir = Quiq::Path->expandTilde(shift); | |||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | 0 | my $dryRun = $self->{'dryRun'}; | |||||||||||||||||||||||||||
| 458 | 0 | my $log = $self->{'log'}; | |||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | 0 | ▶ | if ($log || $dryRun) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$log or $dryRun
MC/DC0%0/2
$log or $dryRun
$log
$dryRun
Truth table0%0/3
A or B
A= $logB= $dryRun
| |||||||||||||||||||||||||||||
| 461 | 0 | $self->_logCmd("cd $dir"); | |||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | 0 | my $cwd = Quiq::Process->cwd; | |||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | 0 | ▶ | unless ($dryRun) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 467 | 0 | my $t0 = Time::HiRes::gettimeofday; | |||||||||||||||||||||||||||
| 468 | 0 | Quiq::Process->cwd($dir); | |||||||||||||||||||||||||||
| 469 | 0 | my $t1 = Time::HiRes::gettimeofday; | |||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | 0 | ▶ | if ($log && $self->{'time'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$log and $self->{"time"}
MC/DC0%0/2
$log and $self->{"time"}
$log
$self->{"time"}
Truth table0%0/3
A and B
A= $logB= $self->{"time"}
| |||||||||||||||||||||||||||||
| 472 | 0 | my $fd = $self->{'logDest'}; | |||||||||||||||||||||||||||
| 473 | 0 | printf $fd "/* %4.2f sec */\n",$t1-$t0; | |||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||
| 476 | 0 | push @{$self->{'dirStack'}},$cwd; | |||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | 0 | return; | |||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | =head3 back() - Wechsele ins vorige Arbeitsverzeichnis zurück | ||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | =head4 Synopsis | ||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | $this->back; | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | =cut | ||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | 0 | ▶ | sub back { | ||||||||||||||||||||||||||
|
Subroutine
back: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 494 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||
| 496 | 0 | my $dir = pop @{$self->{'dirStack'}}; | |||||||||||||||||||||||||||
| 497 | 0 | ▶ | unless ($dir) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 498 | 0 | return; | |||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | 0 | my $dryRun = $self->{'dryRun'}; | |||||||||||||||||||||||||||
| 502 | 0 | my $log = $self->{'log'}; | |||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | 0 | ▶ | if ($log || $dryRun) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$log or $dryRun
MC/DC0%0/2
$log or $dryRun
$log
$dryRun
Truth table0%0/3
A or B
A= $logB= $dryRun
| |||||||||||||||||||||||||||||
| 505 | 0 | $self->_logCmd("cd $dir"); | |||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | 0 | ▶ | unless ($dryRun) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 509 | 0 | my $t0 = Time::HiRes::gettimeofday; | |||||||||||||||||||||||||||
| 510 | 0 | Quiq::Process->cwd($dir); | |||||||||||||||||||||||||||
| 511 | 0 | my $t1 = Time::HiRes::gettimeofday; | |||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | 0 | ▶ | if ($log && $self->{'time'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$log and $self->{"time"}
MC/DC0%0/2
$log and $self->{"time"}
$log
$self->{"time"}
Truth table0%0/3
A and B
A= $logB= $self->{"time"}
| |||||||||||||||||||||||||||||
| 514 | 0 | my $fd = $self->{'logDest'}; | |||||||||||||||||||||||||||
| 515 | 0 | printf $fd "/* %.2f */\n",$t1-$t0; | |||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||
| 519 | 0 | return; | |||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | =head3 backDir() - Voriges Arbeitsverzeichnis | ||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | =head4 Synopsis | ||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||
| 528 | $dir = $sh->backDir; | ||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||
| 530 | =head4 Returns | ||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | Verzeichnispfad (String) | ||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | =head4 Description | ||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | Liefere das oberste Element des Verzeichnis-Stack ohne den Stack | ||||||||||||||||||||||||||||
| 537 | zu verändern. | ||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | =cut | ||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | 0 | ▶ | sub backDir { | ||||||||||||||||||||||||||
|
Subroutine
backDir: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 544 | 0 | return shift->{'dirStack'}->[-1]; | |||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | =head2 Private Methoden | ||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | =head3 _logCmd() - Logge Kommandozeile | ||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||
| 553 | =head4 Synopsis | ||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | $sh->_logCmd($cmd); | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | =head4 Description | ||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||
| 559 | Schreibe die Kommandozeile $cmd auf die Loghandle. | ||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | =cut | ||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||
| 563 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||
| 565 | 0 | ▶ | sub _logCmd { | ||||||||||||||||||||||||||
|
Subroutine
_logCmd: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 566 | 0 | my ($self,$cmd) = @_; | |||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | 0 | ▶ | if (my $sub = $self->{'logRewrite'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 569 | 0 | $cmd = $sub->($self,$cmd); | |||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||
| 572 | 0 | my $esc = $self->{'cmdAnsiColor'}; | |||||||||||||||||||||||||||
| 573 | 0 | my $a = Quiq::AnsiColor->new($esc); | |||||||||||||||||||||||||||
| 574 | 0 | $cmd = sprintf '%s%s',$self->{'cmdPrefix'},$a->str($esc,$cmd); | |||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||
| 576 | 0 | my $fd = $self->{'logDest'}; | |||||||||||||||||||||||||||
| 577 | 0 | print $fd $cmd,"\n"; | |||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||
| 579 | 0 | return; | |||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||
| 582 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||
| 584 | =head1 VERSION | ||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | 1.240 | ||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||
| 590 | Frank Seitz, L<http://fseitz.de/> | ||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||
| 592 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||
| 594 | Copyright (C) 2026 Frank Seitz | ||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||
| 596 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||
| 598 | This code is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 599 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | =cut | ||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||
| 605 | 270 | 1; | |||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||
| 607 | # eof | ||||||||||||||||||||||||||||