mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-11-22 22:17:54 +00:00
parallel: implemented --tag
This commit is contained in:
parent
d0f6c9a0aa
commit
9fad573774
39
src/parallel
39
src/parallel
|
@ -398,6 +398,7 @@ sub options_hash {
|
||||||
"shellquote|shell_quote|shell-quote" => \$::opt_shellquote,
|
"shellquote|shell_quote|shell-quote" => \$::opt_shellquote,
|
||||||
"nice=i" => \$::opt_nice,
|
"nice=i" => \$::opt_nice,
|
||||||
"timeout=i" => \$::opt_timeout,
|
"timeout=i" => \$::opt_timeout,
|
||||||
|
"tag" => \$::opt_tag,
|
||||||
"onall" => \$::opt_onall,
|
"onall" => \$::opt_onall,
|
||||||
"nonall" => \$::opt_nonall,
|
"nonall" => \$::opt_nonall,
|
||||||
"sshlogin|S=s" => \@::opt_sshlogin,
|
"sshlogin|S=s" => \@::opt_sshlogin,
|
||||||
|
@ -1678,6 +1679,11 @@ sub usage {
|
||||||
"--recstart str Record start separator for --pipe.",
|
"--recstart str Record start separator for --pipe.",
|
||||||
"",
|
"",
|
||||||
"See 'man $Global::progname' for details",
|
"See 'man $Global::progname' for details",
|
||||||
|
"",
|
||||||
|
"When using GNU Parallel for a publication please cite:",
|
||||||
|
"",
|
||||||
|
"O. Tange (2011): GNU Parallel - The Command-Line Power Tool,",
|
||||||
|
";login: The USENIX Magazine, February 2011:42-47.",
|
||||||
"");
|
"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3461,21 +3467,36 @@ sub print {
|
||||||
if($Global::debug) {
|
if($Global::debug) {
|
||||||
print STDERR "ERR:\n";
|
print STDERR "ERR:\n";
|
||||||
}
|
}
|
||||||
my $buf;
|
if($::opt_tag) {
|
||||||
while(sysread($err,$buf,1000_000)) {
|
my $tag = $self->{'commandline'}->args_as_string();
|
||||||
print STDERR $buf;
|
while(<$err>) {
|
||||||
|
print STDERR $tag,"\t",$_;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
my $buf;
|
||||||
|
while(sysread($err,$buf,1000_000)) {
|
||||||
|
print STDERR $buf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
flush STDERR;
|
flush STDERR;
|
||||||
|
|
||||||
if($::opt_files) {
|
if($::opt_files) {
|
||||||
print STDOUT $self->{'stdoutfilename'},"\n";
|
print STDOUT $self->{'stdoutfilename'},"\n";
|
||||||
} else {
|
} else {
|
||||||
|
my $buf;
|
||||||
seek $out, 0, 0;
|
seek $out, 0, 0;
|
||||||
if($Global::debug) {
|
if($Global::debug) {
|
||||||
print STDOUT "OUT:\n";
|
print STDOUT "OUT:\n";
|
||||||
}
|
}
|
||||||
while(sysread($out,$buf,1000_000)) {
|
if($::opt_tag) {
|
||||||
print STDOUT $buf;
|
my $tag = $self->{'commandline'}->args_as_string();
|
||||||
|
while(<$out>) {
|
||||||
|
print STDOUT $tag,"\t",$_;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
while(sysread($out,$buf,1000_000)) {
|
||||||
|
print STDOUT $buf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
flush STDOUT;
|
flush STDOUT;
|
||||||
::debug("<<joboutput $command\n");
|
::debug("<<joboutput $command\n");
|
||||||
|
@ -3691,6 +3712,14 @@ sub number_of_args {
|
||||||
return $#{$self->{'arg_list'}}+1;
|
return $#{$self->{'arg_list'}}+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub args_as_string {
|
||||||
|
# Returns:
|
||||||
|
# all unmodified arguments joined with ' ' (similar to {})
|
||||||
|
my $self = shift;
|
||||||
|
return (join " ", map { $_->orig() }
|
||||||
|
map { @$_ } @{$self->{'arg_list'}});
|
||||||
|
}
|
||||||
|
|
||||||
sub len {
|
sub len {
|
||||||
# The length of the command line with args substituted
|
# The length of the command line with args substituted
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
|
@ -1148,6 +1148,12 @@ and it will open a tty for the job. When the job is done, the next job
|
||||||
will get the tty.
|
will get the tty.
|
||||||
|
|
||||||
|
|
||||||
|
=item B<--tag>
|
||||||
|
|
||||||
|
Tag lines with arguments. Each output line will be prepended with the
|
||||||
|
arguments and TAB (\t).
|
||||||
|
|
||||||
|
|
||||||
=item B<--tmpdir> I<dirname>
|
=item B<--tmpdir> I<dirname>
|
||||||
|
|
||||||
Directory for temporary files. GNU B<parallel> normally buffers output
|
Directory for temporary files. GNU B<parallel> normally buffers output
|
||||||
|
|
|
@ -12,4 +12,11 @@ echo '### Test --use-cpus-instead-of-cores'
|
||||||
echo 'Cores should complete first on machines with less than 4 physical CPUs'
|
echo 'Cores should complete first on machines with less than 4 physical CPUs'
|
||||||
wait
|
wait
|
||||||
|
|
||||||
|
echo '### Test --tag ::: a ::: b'
|
||||||
|
stdout parallel -k --tag -j1 echo stderr-{.} ">&2;" echo stdout-{} ::: a ::: b
|
||||||
|
|
||||||
|
echo '### Test --tag ::: a b'
|
||||||
|
stdout parallel -k --tag -j1 echo stderr-{.} ">&2;" echo stdout-{} ::: a b
|
||||||
|
|
||||||
|
echo '### Test --tag -X ::: a b'
|
||||||
|
stdout parallel -k --tag -X -j1 echo stderr-{.} ">&2;" echo stdout-{} ::: a b
|
||||||
|
|
|
@ -6,3 +6,14 @@
|
||||||
Cores should complete first on machines with less than 4 physical CPUs
|
Cores should complete first on machines with less than 4 physical CPUs
|
||||||
cores done
|
cores done
|
||||||
CPUs done
|
CPUs done
|
||||||
|
### Test --tag ::: a ::: b
|
||||||
|
a b stderr-a b
|
||||||
|
a b stdout-a b
|
||||||
|
### Test --tag ::: a b
|
||||||
|
a stderr-a
|
||||||
|
a stdout-a
|
||||||
|
b stderr-b
|
||||||
|
b stdout-b
|
||||||
|
### Test --tag -X ::: a b
|
||||||
|
a b stderr-a stderr-b
|
||||||
|
a b stdout-a stdout-b
|
||||||
|
|
Loading…
Reference in a new issue