{"thread":{"id":"3446","subject":"[PATCH] Convert open(\"-|\") to qx{} calls","startedAt":"2006-02-23T14:33:17Z","lastAt":"2006-02-24T15:25:47Z","messageCount":13,"participants":["Johannes Schindelin","Alex Riesen","Randal L. Schwartz","Junio C Hamano","Rogan Dawes"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"16619","messageId":"Pine.LNX.4.63.0602231532470.29635@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"3446","inReplyTo":null,"subject":"[PATCH] Convert open(\"-|\") to qx{} calls","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-02-23T14:33:17Z","receivedAt":"2006-02-23T14:33:17Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n\tSince of these 4, I only use cvsimport myself, I could only test\n\tthat. Could someone who uses the others give them a hard beating?\n\n git-cvsimport.perl  |   64 +++++++++++++++++++--------------------------------\n git-rerere.perl     |    9 ++-----\n git-send-email.perl |    9 ++-----\n git-svnimport.perl  |   62 ++++++++++++++-----------------------------------\n 4 files changed, 46 insertions(+), 98 deletions(-)\n\nb37d21c223fdc0ef7fc6af889432f6b51ac82992\ndiff --git a/git-cvsimport.perl b/git-cvsimport.perl\nindex b46469a..da009f2 100755\n--- a/git-cvsimport.perl\n+++ b/git-cvsimport.perl\n@@ -478,9 +478,9 @@ unless(-d $git_dir) {\n \t\t       \"Either use the correct '-o branch' option,\\n\".\n \t\t       \"or import to a new repository.\\n\";\n \n-\topen(F, \"git-symbolic-ref HEAD |\") or\n-\t\tdie \"Cannot run git-symbolic-ref: $!\\n\";\n-\tchomp ($last_branch = <F>);\n+\t$last_branch = qx{git-symbolic-ref HEAD};\n+\t!$? or exit $?;\n+\tchomp ($last_branch);\n \t$last_branch = basename($last_branch);\n \tclose(F);\n \tunless($last_branch) {\n@@ -516,13 +516,12 @@ EOM\n \t\t\tor die \"Bad head branch: $head: $!\\n\";\n \t\tchomp(my $ftag = <F>);\n \t\tclose(F);\n-\t\topen(F,\"git-cat-file commit $ftag |\");\n-\t\twhile(<F>) {\n+\t\tforeach (qx{git-cat-file commit $ftag}) {\n \t\t\tnext unless /^author\\s.*\\s(\\d+)\\s[-+]\\d{4}$/;\n \t\t\t$branch_date{$head} = $1;\n \t\t\tlast;\n \t\t}\n-\t\tclose(F);\n+\t\t!$? or exit $?;\n \t}\n \tclosedir(D);\n }\n@@ -538,24 +537,21 @@ if ($opt_A) {\n \twrite_author_info(\"$git_dir/cvs-authors\");\n }\n \n-my $pid = open(CVS,\"-|\");\n-die \"Cannot fork: $!\\n\" unless defined $pid;\n-unless($pid) {\n-\tmy @opt;\n-\t@opt = split(/,/,$opt_p) if defined $opt_p;\n-\tunshift @opt, '-z', $opt_z if defined $opt_z;\n-\tunshift @opt, '-q'         unless defined $opt_v;\n-\tunless (defined($opt_p) && $opt_p =~ m/--no-cvs-direct/) {\n-\t\tpush @opt, '--cvs-direct';\n-\t}\n-\tif ($opt_P) {\n-\t    exec(\"cat\", $opt_P);\n-\t} else {\n-\t    exec(\"cvsps\",\"--norc\",@opt,\"-u\",\"-A\",'--root',$opt_d,$cvs_tree);\n-\t    die \"Could not start cvsps: $!\\n\";\n-\t}\n+my @opt;\n+@opt = split(/,/,$opt_p) if defined $opt_p;\n+unshift @opt, '-z', $opt_z if defined $opt_z;\n+unshift @opt, '-q'         unless defined $opt_v;\n+unless (defined($opt_p) && $opt_p =~ m/--no-cvs-direct/) {\n+\tpush @opt, '--cvs-direct';\n }\n \n+my @input;\n+if ($opt_P) {\n+    @input = qx{cat $opt_P};\n+} else {\n+    @input = qx{cvsps --norc opt -u -A --root $opt_d $cvs_tree};\n+    !$? or exit $?;\n+}\n \n ## cvsps output:\n #---------------------\n@@ -603,17 +599,11 @@ my $commit = sub {\n \t\tdie \"Cannot add files: $?\\n\" if $?;\n \t}\n \n-\t$pid = open(C,\"-|\");\n-\tdie \"Cannot fork: $!\" unless defined $pid;\n-\tunless($pid) {\n-\t\texec(\"git-write-tree\");\n-\t\tdie \"Cannot exec git-write-tree: $!\\n\";\n-\t}\n-\tchomp(my $tree = <C>);\n+\tmy $tree = qx{git-write-tree};\n+\t!$? or exit $?;\n+\tchomp($tree);\n \tlength($tree) == 40\n \t\tor die \"Cannot get tree id ($tree): $!\\n\";\n-\tclose(C)\n-\t\tor die \"Error running git-write-tree: $?\\n\";\n \tprint \"Tree ID $tree\\n\" if $opt_v;\n \n \tmy $parent = \"\";\n@@ -734,7 +724,7 @@ my $commit = sub {\n \t}\n };\n \n-while(<CVS>) {\n+foreach (@input) {\n \tchomp;\n \tif($state == 0 and /^-+$/) {\n \t\t$state = 1;\n@@ -846,15 +836,9 @@ while(<CVS>) {\n \t\t\tprint \"Drop $fn\\n\" if $opt_v;\n \t\t} else {\n \t\t\tprint \"\".($init ? \"New\" : \"Update\").\" $fn: $size bytes\\n\" if $opt_v;\n-\t\t\tmy $pid = open(my $F, '-|');\n-\t\t\tdie $! unless defined $pid;\n-\t\t\tif (!$pid) {\n-\t\t\t    exec(\"git-hash-object\", \"-w\", $tmpname)\n-\t\t\t\tor die \"Cannot create object: $!\\n\";\n-\t\t\t}\n-\t\t\tmy $sha = <$F>;\n+\t\t\tmy $sha = qx{git-hash-object -w $tmpname};\n+\t\t\t!$? or exit $?;\n \t\t\tchomp $sha;\n-\t\t\tclose $F;\n \t\t\tmy $mode = pmode($cvs->{'mode'});\n \t\t\tpush(@new,[$mode, $sha, $fn]); # may be resurrected!\n \t\t}\ndiff --git a/git-rerere.perl b/git-rerere.perl\nindex d3664ff..0dd04c5 100755\n--- a/git-rerere.perl\n+++ b/git-rerere.perl\n@@ -131,20 +131,15 @@ sub record_preimage {\n sub find_conflict {\n \tmy $in;\n \tlocal $/ = \"\\0\";\n-\tmy $pid = open($in, '-|');\n-\tdie \"$!\" unless defined $pid;\n-\tif (!$pid) {\n-\t\texec(qw(git ls-files -z -u)) or die \"$!: ls-files\";\n-\t}\n \tmy %path = ();\n \tmy @path = ();\n-\twhile (<$in>) {\n+\tforeach (qx{git-ls-files -z -u}) {\n \t\tchomp;\n \t\tmy ($mode, $sha1, $stage, $path) =\n \t\t    /^([0-7]+) ([0-9a-f]{40}) ([123])\\t(.*)$/s;\n \t\t$path{$path} |= (1 << $stage);\n \t}\n-\tclose $in;\n+\t!$? or exit $?;\n \twhile (my ($path, $status) = each %path) {\n \t\tif ($status == 14) { push @path, $path; }\n \t}\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex b0d095b..bd8fae6 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -62,13 +62,8 @@ my $rc = GetOptions(\"from=s\" => \\$from,\n sub gitvar {\n     my ($var) = @_;\n     my $fh;\n-    my $pid = open($fh, '-|');\n-    die \"$!\" unless defined $pid;\n-    if (!$pid) {\n-\texec('git-var', $var) or die \"$!\";\n-    }\n-    my ($val) = <$fh>;\n-    close $fh or die \"$!\";\n+    my ($val) = qx{git-var $var};\n+    !$? or exit $?;\n     chomp($val);\n     return $val;\n }\ndiff --git a/git-svnimport.perl b/git-svnimport.perl\nindex ee2940f..6094a11 100755\n--- a/git-svnimport.perl\n+++ b/git-svnimport.perl\n@@ -218,11 +218,10 @@ unless(-d $git_dir) {\n \t-f \"$git_dir/svn2git\"\n \t\tor die \"'$git_dir/svn2git' does not exist.\\n\".\n \t\t       \"You need that file for incremental imports.\\n\";\n-\topen(F, \"git-symbolic-ref HEAD |\") or\n-\t\tdie \"Cannot run git-symbolic-ref: $!\\n\";\n-\tchomp ($last_branch = <F>);\n+\t$last_brach = qx{git-symbolic-ref HEAD};\n+\t!$? or exit $?;\n+\tchomp $last_branch;\n \t$last_branch = basename($last_branch);\n-\tclose(F);\n \tunless($last_branch) {\n \t\twarn \"Cannot read the last branch name: $! -- assuming 'master'\\n\";\n \t\t$last_branch = \"master\";\n@@ -321,15 +320,9 @@ sub get_file($$$) {\n \t\treturn undef unless defined $name;\n \t}\n \n-\tmy $pid = open(my $F, '-|');\n-\tdie $! unless defined $pid;\n-\tif (!$pid) {\n-\t    exec(\"git-hash-object\", \"-w\", $name)\n-\t\tor die \"Cannot create object: $!\\n\";\n-\t}\n-\tmy $sha = <$F>;\n+\tmy $sha = qx{git-hash-object -w $name};\n+\t!$? or exit $?;\n \tchomp $sha;\n-\tclose $F;\n \tunlink $name;\n \tmy $mode = \"0644\"; # SV does not seem to store any file modes\n \treturn [$mode, $sha, $path];\n@@ -401,14 +394,8 @@ sub copy_path($$$$$$$$) {\n \t\t\t$srcpath =~ s#/*$#/#;\n \t}\n \t\n-\tmy $pid = open my $f,'-|';\n-\tdie $! unless defined $pid;\n-\tif (!$pid) {\n-\t\texec(\"git-ls-tree\",\"-r\",\"-z\",$gitrev,$srcpath)\n-\t\t\tor die $!;\n-\t}\n \tlocal $/ = \"\\0\";\n-\twhile(<$f>) {\n+\tforeach (qx{git-ls-tree -r -z $gitrev $srcpath}) {\n \t\tchomp;\n \t\tmy($m,$p) = split(/\\t/,$_,2);\n \t\tmy($mode,$type,$sha1) = split(/ /,$m);\n@@ -420,8 +407,7 @@ sub copy_path($$$$$$$$) {\n \t\t}\n \t\tpush(@$new,[$mode,$sha1,$p]);\t\n \t}\n-\tclose($f) or\n-\t\tprint STDERR \"$newrev:$newbranch: could not list files in $oldpath \\@ $rev\\n\";\n+\t!$? or exit $?;\n }\n \n sub commit {\n@@ -472,9 +458,8 @@ sub commit {\n \n \tmy $rev;\n \tif($revision > $opt_s and defined $parent) {\n-\t\topen(H,\"git-rev-parse --verify $parent |\");\n-\t\t$rev = <H>;\n-\t\tclose(H) or do {\n+\t\t$rev = qx{git-rev-parse --verify $parent};\n+\t\t!$? or do {\n \t\t\tprint STDERR \"$revision: cannot find commit '$parent'!\\n\";\n \t\t\treturn;\n \t\t};\n@@ -555,25 +540,20 @@ sub commit {\n \t\t}\n \n \t\twhile(@old) {\n-\t\t\tmy @o1;\n+\t\t\tmy @o2;\n \t\t\tif(@old > 55) {\n-\t\t\t\t@o1 = splice(@old,0,50);\n+\t\t\t\t@o2 = splice(@old,0,50);\n \t\t\t} else {\n-\t\t\t\t@o1 = @old;\n+\t\t\t\t@o2 = @old;\n \t\t\t\t@old = ();\n \t\t\t}\n-\t\t\tmy $pid = open my $F, \"-|\";\n-\t\t\tdie \"$!\" unless defined $pid;\n-\t\t\tif (!$pid) {\n-\t\t\t\texec(\"git-ls-files\", \"-z\", @o1) or die $!;\n-\t\t\t}\n-\t\t\t@o1 = ();\n+\t\t\tmy @o1 = ();\n \t\t\tlocal $/ = \"\\0\";\n-\t\t\twhile(<$F>) {\n+\t\t\tforeach (qx{git-ls-files -z @o1}) {\n \t\t\t\tchomp;\n \t\t\t\tpush(@o1,$_);\n \t\t\t}\n-\t\t\tclose($F);\n+\t\t\t!$? or exit $?;\n \n \t\t\twhile(@o1) {\n \t\t\t\tmy @o2;\n@@ -600,17 +580,11 @@ sub commit {\n \t\t\tdie \"Cannot add files: $?\\n\" if $?;\n \t\t}\n \n-\t\tmy $pid = open(C,\"-|\");\n-\t\tdie \"Cannot fork: $!\" unless defined $pid;\n-\t\tunless($pid) {\n-\t\t\texec(\"git-write-tree\");\n-\t\t\tdie \"Cannot exec git-write-tree: $!\\n\";\n-\t\t}\n-\t\tchomp(my $tree = <C>);\n+\t\tmy $tree = qx{git-write-tree};\n+\t\t!$? or exit $?;\n+\t\tchomp($tree);\n \t\tlength($tree) == 40\n \t\t\tor die \"Cannot get tree id ($tree): $!\\n\";\n-\t\tclose(C)\n-\t\t\tor die \"Error running git-write-tree: $?\\n\";\n \t\tprint \"Tree ID $tree\\n\" if $opt_v;\n \n \t\tmy $pr = IO::Pipe->new() or die \"Cannot open pipe: $!\\n\";\n-- \n1.2.3.gb37d\n"},{"id":"16622","messageId":"81b0412b0602230738s3445bd86h2d1d670e0ef5daed@mail.gmail.com","threadId":"3446","inReplyTo":"Pine.LNX.4.63.0602231532470.29635@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Convert open(\"-|\") to qx{} calls","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2006-02-23T15:38:48Z","receivedAt":"2006-02-23T15:38:48Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"On 2/23/06, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n>       Since of these 4, I only use cvsimport myself, I could only test\n>       that. Could someone who uses the others give them a hard beating?\n\nI can't really test them (no svn and cvs, and locked down network), but I took\na look at the patches. Hope it helps.\n\ngit-cvsimport:\n\n> -               open(F,\"git-cat-file commit $ftag |\");\n> -               while(<F>) {\n> +               foreach (qx{git-cat-file commit $ftag}) {\n>                         next unless /^author\\s.*\\s(\\d+)\\s[-+]\\d{4}$/;\n\nAre you sure you don't need quoting/safe pipe here?\nOr is it a CVS tag?\n\n> +} else {\n> +    @input = qx{cvsps --norc opt -u -A --root $opt_d $cvs_tree};\n> +    !$? or exit $?;\n\nSame here. $cvs_tree can contain any filesystem-allowed character.\n\ngit-svnimport:\n\n> -                       my $sha = <$F>;\n> +                       my $sha = qx{git-hash-object -w $tmpname};\n> +                       !$? or exit $?;\n\nIs $tmpname safe?\n\n> -       my $sha = <$F>;\n> +       my $sha = qx{git-hash-object -w $name};\n> +       !$? or exit $?;\n\nIs $name safe?\n\n> -       while(<$f>) {\n> +       foreach (qx{git-ls-tree -r -z $gitrev $srcpath}) {\n>                 chomp;\n\nIs $srcpath safe?\n\n> -                       while(<$F>) {\n> +                       foreach (qx{git-ls-files -z @o1}) {\n\n@o1 must contain filenames. Can be dangerous\n"},{"id":"16623","messageId":"86hd6qgit5.fsf@blue.stonehenge.com","threadId":"3446","inReplyTo":"81b0412b0602230738s3445bd86h2d1d670e0ef5daed@mail.gmail.com","subject":"Re: [PATCH] Convert open(\"-|\") to qx{} calls","fromName":"Randal L. Schwartz","fromEmail":"merlyn@stonehenge.com","sentAt":"2006-02-23T16:07:34Z","receivedAt":"2006-02-23T16:07:34Z","isPatch":true,"sender":{"key":"merlyn@stonehenge.com","avatar":"https://gravatar.com/avatar/dc528d210743ff0333e6213f9ee7b33b23f1b7bc1f3c5a8c2d819074ecd7ab19?d=mp&s=160"},"body":">>>>> \"Alex\" == Alex Riesen <raa.lkml@gmail.com> writes:\n\nAlex> Is $tmpname safe?\n\n>> -       my $sha = <$F>;\n>> +       my $sha = qx{git-hash-object -w $name};\n>> +       !$? or exit $?;\n\nAlex> Is $name safe?\n\n>> -       while(<$f>) {\n>> +       foreach (qx{git-ls-tree -r -z $gitrev $srcpath}) {\n>> chomp;\n\nAlex> Is $srcpath safe?\n\n>> -                       while(<$F>) {\n>> +                       foreach (qx{git-ls-files -z @o1}) {\n\nAlex> @o1 must contain filenames. Can be dangerous\n\nConvert all of these to use \"safe_qx\" (perl 5.6 compatible):\n\n    sub safe_qx {\n      defined (my $pid = open my $kid, \"-|\") or die \"Cannot fork: $!\";\n      unless ($pid) { # child does:\n        exec @_;\n        die \"Cannot exec @_: $!\";\n      }\n      my $result = do { local $/; <$kid> };\n      close $kid;                   # sets $?\n      return $result;\n    }\n\nmy $result = safe_qx('some shell command');\nmy $other_result = safe_qx('git-ls-tree', '-r', '-z', $gitrev, $srcpath);\n\nArgs are safe, as if being passed to system/exec, so a single arg\ncan be a shell command, multiargs are passed arg-by-arg to a single\nexec target.  $? is set correctly.\n\n-- \nRandal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095\n<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>\nPerl/Unix/security consulting, Technical writing, Comedy, etc. etc.\nSee PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!\n"},{"id":"16625","messageId":"7v1wxuhsgw.fsf@assigned-by-dhcp.cox.net","threadId":"3446","inReplyTo":"86hd6qgit5.fsf@blue.stonehenge.com","subject":"Re: [PATCH] Convert open(\"-|\") to qx{} calls","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-02-23T17:53:35Z","receivedAt":"2006-02-23T17:53:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"merlyn@stonehenge.com (Randal L. Schwartz) writes:\n\n> Convert all of these to use \"safe_qx\" (perl 5.6 compatible):\n>\n>     sub safe_qx {\n>       defined (my $pid = open my $kid, \"-|\") or die \"Cannot fork: $!\";\n>...\n\nIIRC, that is backwards.  The thread's conversion is not about\n5.6 vs 5.8.  The conversion like what you suggested above was\ndone, but the thing is, and Alex's Perl is unhappy about it.\n\nThe version of Perl Alex has to use claims to be 5.8, but does\nnot understand open($kid, '-|'), and he is trying to come up\nwith a workaround.\n\nI wish Perl had a stricter trademark policy that required\nlanguage features to be fully ported for an implementation to\nuse that name ;-).\n"},{"id":"16626","messageId":"863bi9hq6u.fsf@blue.stonehenge.com","threadId":"3446","inReplyTo":"7v1wxuhsgw.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Convert open(\"-|\") to qx{} calls","fromName":"Randal L. Schwartz","fromEmail":"merlyn@stonehenge.com","sentAt":"2006-02-23T18:42:49Z","receivedAt":"2006-02-23T18:42:49Z","isPatch":true,"sender":{"key":"merlyn@stonehenge.com","avatar":"https://gravatar.com/avatar/dc528d210743ff0333e6213f9ee7b33b23f1b7bc1f3c5a8c2d819074ecd7ab19?d=mp&s=160"},"body":">>>>> \"Junio\" == Junio C Hamano <junkio@cox.net> writes:\n\nJunio> The version of Perl Alex has to use claims to be 5.8, but does\nJunio> not understand open($kid, '-|'), and he is trying to come up\nJunio> with a workaround.\n\nAhh, the problem is activestate then.  If that's the case, then amend the code\nwith a check for $^O (operating system) that falls back to a qx if on\nactivestate, and hope that filenames aren't a problem.  Unfortunately, I don't\nknow enough about that to fix it.\n\nBut whatever you do, *don't* replace safe_qx with qx() for all other systems,\nor you'll be opening up a can of worms for those of us on sensible systems.\n\n-- \nRandal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095\n<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>\nPerl/Unix/security consulting, Technical writing, Comedy, etc. etc.\nSee PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!\n"},{"id":"16630","messageId":"Pine.LNX.4.63.0602232039160.30630@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"3446","inReplyTo":"863bi9hq6u.fsf@blue.stonehenge.com","subject":"Re: [PATCH] Convert open(\"-|\") to qx{} calls","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-02-23T19:41:37Z","receivedAt":"2006-02-23T19:41:37Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 23 Feb 2006, Randal L. Schwartz wrote:\n\n> >>>>> \"Junio\" == Junio C Hamano <junkio@cox.net> writes:\n> \n> Junio> The version of Perl Alex has to use claims to be 5.8, but does\n> Junio> not understand open($kid, '-|'), and he is trying to come up\n> Junio> with a workaround.\n> \n> Ahh, the problem is activestate then.  If that's the case, then amend \n> the code with a check for $^O (operating system) that falls back to a qx \n> if on activestate, and hope that filenames aren't a problem.  \n> Unfortunately, I don't know enough about that to fix it.\n\nNow that our local Perl guru joined the discussion, may I ask what is, and \nwhat is not quoted when put inside qx{}? I had the impression that all \narguments are quoted, except that variables are resolved first. Was that \nwrong? IOW does\n\n\tqx{bash $variable}\n\nquote the value of $variable, or not?\n\nCiao,\nDscho\n"},{"id":"16636","messageId":"86lkw1g647.fsf@blue.stonehenge.com","threadId":"3446","inReplyTo":"Pine.LNX.4.63.0602232039160.30630@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Convert open(\"-|\") to qx{} calls","fromName":"Randal L. Schwartz","fromEmail":"merlyn@stonehenge.com","sentAt":"2006-02-23T20:41:44Z","receivedAt":"2006-02-23T20:41:44Z","isPatch":true,"sender":{"key":"merlyn@stonehenge.com","avatar":"https://gravatar.com/avatar/dc528d210743ff0333e6213f9ee7b33b23f1b7bc1f3c5a8c2d819074ecd7ab19?d=mp&s=160"},"body":">>>>> \"Johannes\" == Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\nJohannes> Now that our local Perl guru joined the discussion, may I ask what\nJohannes> is, and what is not quoted when put inside qx{}?\n\nNothing is quoted.  Your string acts as if it was XXX in:\n\n        sh -c 'XXX'\n\nso any quoting is entirely on your own.  Thus, without the multi-arg exec in\nmy proposed replacement, you can get shell-ish interactions that can ruin your\nday pretty bad.\n\nJohannes>  I had the\nJohannes> impression that all arguments are quoted, except that variables are\nJohannes> resolved first. Was that wrong? IOW does\n\nJohannes> \tqx{bash $variable}\n\nJohannes> quote the value of $variable, or not?\n\nThe Perl $variable is expanded to its current contents.  But suppose the\ncontents are `date` (including the backquotes).  That would mean that a shell\nwould execute a date command, and *its* output would then contribute further\nto the command invocation.\n\n-- \nRandal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095\n<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>\nPerl/Unix/security consulting, Technical writing, Comedy, etc. etc.\nSee PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!\n"},{"id":"16637","messageId":"20060223211403.GB5827@steel.home","threadId":"3446","inReplyTo":"86lkw1g647.fsf@blue.stonehenge.com","subject":"Re: [PATCH] Convert open(\"-|\") to qx{} calls","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2006-02-23T21:14:03Z","receivedAt":"2006-02-23T21:14:03Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Randal L. Schwartz, Thu, Feb 23, 2006 21:41:44 +0100:\n> Johannes> Now that our local Perl guru joined the discussion, may I ask what\n> Johannes> is, and what is not quoted when put inside qx{}?\n> \n> Nothing is quoted.  Your string acts as if it was XXX in:\n> \n>         sh -c 'XXX'\n> \n\nNot so for ActiveState. It'll just run the first non-whitespace word\npassing the rest of the line in its command-line.\nIt's not even worse then to pass it all to cmd/command :)\n"},{"id":"16638","messageId":"863bi9g4jq.fsf@blue.stonehenge.com","threadId":"3446","inReplyTo":"20060223211403.GB5827@steel.home","subject":"Re: [PATCH] Convert open(\"-|\") to qx{} calls","fromName":"Randal L. Schwartz","fromEmail":"merlyn@stonehenge.com","sentAt":"2006-02-23T21:15:37Z","receivedAt":"2006-02-23T21:15:37Z","isPatch":true,"sender":{"key":"merlyn@stonehenge.com","avatar":"https://gravatar.com/avatar/dc528d210743ff0333e6213f9ee7b33b23f1b7bc1f3c5a8c2d819074ecd7ab19?d=mp&s=160"},"body":">>>>> \"Alex\" == Alex Riesen <raa.lkml@gmail.com> writes:\n\nAlex> Randal L. Schwartz, Thu, Feb 23, 2006 21:41:44 +0100:\nJohannes> Now that our local Perl guru joined the discussion, may I ask what\nJohannes> is, and what is not quoted when put inside qx{}?\n>> \n>> Nothing is quoted.  Your string acts as if it was XXX in:\n>> \n>> sh -c 'XXX'\n>> \n\nAlex> Not so for ActiveState. It'll just run the first non-whitespace word\nAlex> passing the rest of the line in its command-line.\nAlex> It's not even worse then to pass it all to cmd/command :)\n\nRight.  That's why I suggest (in a later message) that safe_qx merely\nfall back to qx() on Activestate.  Can't go much more wrong. :)\n\n-- \nRandal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095\n<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>\nPerl/Unix/security consulting, Technical writing, Comedy, etc. etc.\nSee PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!\n"},{"id":"16652","messageId":"43FE9771.4030206@dawes.za.net","threadId":"3446","inReplyTo":"20060223211403.GB5827@steel.home","subject":"Re: [PATCH] Convert open(\"-|\") to qx{} calls","fromName":"Rogan Dawes","fromEmail":"discard@dawes.za.net","sentAt":"2006-02-24T05:19:45Z","receivedAt":"2006-02-24T05:19:45Z","isPatch":true,"sender":{"key":"discard@dawes.za.net","avatar":null},"body":"Alex Riesen wrote:\n> Randal L. Schwartz, Thu, Feb 23, 2006 21:41:44 +0100:\n>> Johannes> Now that our local Perl guru joined the discussion, may I ask what\n>> Johannes> is, and what is not quoted when put inside qx{}?\n>>\n>> Nothing is quoted.  Your string acts as if it was XXX in:\n>>\n>>         sh -c 'XXX'\n>>\n> \n> Not so for ActiveState. It'll just run the first non-whitespace word\n> passing the rest of the line in its command-line.\n> It's not even worse then to pass it all to cmd/command :)\n> \n\nNot true.\n\n > type t\n#!perl -w\n\nprint qx{echo joe & echo joe}.\"\\n\";\n > perl t\njoe\njoe\n\n >\n\nIf the shell was not interpreting the arguments, you would expect to get \n1 line with:\n\njoe & echo joe\n\non it.\n\n > perl -v\nThis is perl, v5.8.7 built for MSWin32-x86-multi-thread\n(with 7 registered patches, see perl -V for more detail)\n\nCopyright 1987-2005, Larry Wall\n\nBinary build 813 [148120] provided by ActiveState http://www.ActiveState.com\nActiveState is a division of Sophos.\nBuilt Jun  6 2005 13:36:37\n\nPerl may be copied only under the terms of either the Artistic License \nor the\nGNU General Public License, which may be found in the Perl 5 source kit.\n\nComplete documentation for Perl, including FAQ lists, should be found on\nthis system using `man perl' or `perldoc perl'.  If you have access to the\nInternet, point your browser at http://www.perl.org/, the Perl Home Page.\n\nRegards,\n\nRogan\n"},{"id":"16672","messageId":"81b0412b0602240527v5d617111sc33e627ff3e1641c@mail.gmail.com","threadId":"3446","inReplyTo":"43FE9771.4030206@dawes.za.net","subject":"Re: [PATCH] Convert open(\"-|\") to qx{} calls","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2006-02-24T13:27:58Z","receivedAt":"2006-02-24T13:27:58Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"On 2/24/06, Rogan Dawes <discard@dawes.za.net> wrote:\n> Alex Riesen wrote:\n> > Randal L. Schwartz, Thu, Feb 23, 2006 21:41:44 +0100:\n> >> Johannes> Now that our local Perl guru joined the discussion, may I ask what\n> >> Johannes> is, and what is not quoted when put inside qx{}?\n> >>\n> >> Nothing is quoted.  Your string acts as if it was XXX in:\n> >>\n> >>         sh -c 'XXX'\n> >>\n> >\n> > Not so for ActiveState. It'll just run the first non-whitespace word\n> > passing the rest of the line in its command-line.\n> > It's not even worse then to pass it all to cmd/command :)\n> >\n>\n> Not true.\n>\n>  > type t\n> #!perl -w\n>\n> print qx{echo joe & echo joe}.\"\\n\";\n>  > perl t\n> joe\n> joe\n>\n\nDoes not seem to be the case here (and yes, I check build 815 too):\n\n$ perl -v\n\nThis is perl, v5.8.6 built for MSWin32-x86-multi-thread\n(with 3 registered patches, see perl -V for more detail)\n\nCopyright 1987-2004, Larry Wall\n\nBinary build 811 provided by ActiveState Corp. http://www.ActiveState.com\nActiveState is a division of Sophos.\nBuilt Dec 13 2004 09:52:01\n...\n\n$ perl -e 'print qx{echo joe & echo joe}.\"\\n\";'\njoe & echo joe\n"},{"id":"16675","messageId":"43FF185C.1080909@dawes.za.net","threadId":"3446","inReplyTo":"81b0412b0602240527v5d617111sc33e627ff3e1641c@mail.gmail.com","subject":"Re: [PATCH] Convert open(\"-|\") to qx{} calls","fromName":"Rogan Dawes","fromEmail":"discard@dawes.za.net","sentAt":"2006-02-24T14:29:48Z","receivedAt":"2006-02-24T14:29:48Z","isPatch":true,"sender":{"key":"discard@dawes.za.net","avatar":null},"body":"Alex Riesen wrote:\n> On 2/24/06, Rogan Dawes <discard@dawes.za.net> wrote:\n> > Not true.\n>>\n>>  > type t\n>> #!perl -w\n>>\n>> print qx{echo joe & echo joe}.\"\\n\";\n>>  > perl t\n>> joe\n>> joe\n>>\n> \n> Does not seem to be the case here (and yes, I check build 815 too):\n> \n> $ perl -v\n> \n> This is perl, v5.8.6 built for MSWin32-x86-multi-thread\n> (with 3 registered patches, see perl -V for more detail)\n> \n> Copyright 1987-2004, Larry Wall\n> \n> Binary build 811 provided by ActiveState Corp. http://www.ActiveState.com\n> ActiveState is a division of Sophos.\n> Built Dec 13 2004 09:52:01\n> ...\n> \n> $ perl -e 'print qx{echo joe & echo joe}.\"\\n\";'\n> joe & echo joe\n\nInteresting. I tried to do that one-liner at a DOS prompt (not cygwin, \nwhich I assume you are using), and I was unable to do so. CMD was seeing \nthe \"&\" first, and splitting the command in 2, namely\n\nperl -e 'print qx joe\n\nand\n\necho joe}.\"\\n\";'\n\nwhich obviously didn't work.\n\nDo you get the same results if you run it from a DOS prompt? and via a file?\n\nRogan\n"},{"id":"16677","messageId":"81b0412b0602240725r38360ca4yf90dcb827ffeccfb@mail.gmail.com","threadId":"3446","inReplyTo":"43FF185C.1080909@dawes.za.net","subject":"Re: [PATCH] Convert open(\"-|\") to qx{} calls","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2006-02-24T15:25:47Z","receivedAt":"2006-02-24T15:25:47Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"On 2/24/06, Rogan Dawes <discard@dawes.za.net> wrote:\n> Interesting. I tried to do that one-liner at a DOS prompt (not cygwin,\n> which I assume you are using), and I was unable to do so.\n\nYes, it was from cygwin's bash.\n\n> Do you get the same results if you run it from a DOS prompt? and via a file?\n\nMicrosoft Windows 2000 [Version 5.00.2195]\n(C) Copyright 1985-2000 Microsoft Corp.\n\nC:\\>perl -e 'print qx{echo joe & echo joe}'\nCan't find string terminator \"'\" anywhere before EOF at -e line 1.\njoe}'\n\nC:\\>perl -e \"print qx{echo joe & echo joe}\"\njoe & echo joe\n\nC:\\>perl x.pl\njoe & echo joe\n\nC:\\>\n"}]}