close $hfile;
}
+#use String::ShellQuote;
sub cmd {
my $cmd = join(' ',@_);
+ # NB 14.12.22 #$cmd =~ s/\$'\\t'/"\t"/g;
+ #$cmd =~ s/(')/\\$1/g;
+# NB 14.12.22 #die $cmd;
+ # NB 14.12.22 my @cmd = `$cmd`;
+ # NB 14.12.22 die "$!" if $?;
+ # NB 14.12.22 return wantarray ? @cmd : join('',@cmd);
my $hcmd;
-#die $_;
- my @cmd = `$cmd`;
- die "$!" if $?;
+ my $pid;
+ die $! unless defined ($pid = open($hcmd,"-|"));
+ if ($pid == 0) {
+ exec "$cmd";
+ }
+ my @cmd = <$hcmd>;
+ close $hcmd;
+ #waitpid $pid,0;
+ die "ERROR $cmd: $!" if $? != 0;
return wantarray ? @cmd : join('',@cmd);
- # NB 13.12.22 $cmd =~ s/"/\\"/g;
- # NB 13.12.22 open reurn pid if command failed, so die never called: open($hcmd,qq/bash -lc "$cmd" |/) or die $!;
- # NB 13.12.22 open($hcmd,"$cmd |") or die $!;
- # NB 13.12.22 my @cmd = <$hcmd>;
- # NB 13.12.22 close $hcmd;
- # NB 13.12.22 return wantarray ? @cmd : join('',@cmd);
}
sub shell_replace {
Find files which contains start and tags >SHELL_REPLACE .. <SHELL_REPLACE.
Execute the command aflter the start tag and replace the lines until the end tag.
Example of file content:
-#>SHELL_REPLACE dbq.php nb meta ls key,val cat=mime.comment format=vim_hash preff=$'\t' name=mimeComment
+#>SHELL_REPLACE Shell command
.....
#<SHELL_REPLACE
let mimeAliases = {
\ 'sh' : 'bash'
\}
-">SHELL_REPLACE dbq.php nb meta ls key,val cat=file.check format=vim_hash preff=$'\t' name=mimeCheck
+">SHELL_REPLACE dbq db=nb t=meta action=table.rows rows.fields=key,val cat=file.check format=vim_hash name=mimeCheck preff="$(printf "\t")"
let mimeCheck = {
\ 'awk' : 'awk < /dev/null --lint=no-ext --file'
\,'bash' : 'bash -c'
\}
"<SHELL_REPLACE
-">SHELL_REPLACE dbq.php nb meta ls key,val cat=mime.comment format=vim_hash preff=$'\t' name=mimeComment
+">SHELL_REPLACE dbq.php nb meta ls key,val cat=mime.comment format=vim_hash preff="$(printf "\t")" name=mimeComment
let mimeComment = {
\ 'bindzone' : ';'
\,'c' : '//'