In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/c24a535b4f4f949d5a0ad1ba1a3a0752344e3558?hp=9f53080ae514a42899f88743c9a5113d4677e9f6>

- Log -----------------------------------------------------------------
commit c24a535b4f4f949d5a0ad1ba1a3a0752344e3558
Author: Tony Cook <[email protected]>
Date:   Wed Oct 22 14:48:32 2014 +1100

    document the limitations of list pipe open on Win32

M       pod/perlport.pod

commit aac983ac3f3f3578c7e34568e0e028c420f3c1f8
Author: Tony Cook <[email protected]>
Date:   Wed Oct 1 16:19:52 2014 +1000

    implement list form of pipe open for Win32

M       t/win32/system.t
M       t/win32/system_tests
M       win32/win32.c
-----------------------------------------------------------------------

Summary of changes:
 pod/perlport.pod     |  3 +++
 t/win32/system.t     |  2 +-
 t/win32/system_tests | 11 ++++++++-
 win32/win32.c        | 66 ++++++++++++++++++++++++++++++++++++++--------------
 4 files changed, 63 insertions(+), 19 deletions(-)

diff --git a/pod/perlport.pod b/pod/perlport.pod
index 8b71a6e..a2f84d3 100644
--- a/pod/perlport.pod
+++ b/pod/perlport.pod
@@ -1867,6 +1867,9 @@ Not implemented. (Android, Win32, VMS, S<Plan 9>, S<RISC 
OS>, VOS)
 
 open to C<|-> and C<-|> are unsupported. (Win32, S<RISC OS>)
 
+List-form pipe opens may fall back to the shell if the first spawn()
+fails. (Win32)
+
 Opening a process does not automatically flush output handles on some
 platforms.  (SunOS, Solaris, HP-UX)
 
diff --git a/t/win32/system.t b/t/win32/system.t
index a6a94cb..939a02d 100644
--- a/t/win32/system.t
+++ b/t/win32/system.t
@@ -151,7 +151,7 @@ while (<$T>) {
            note "want: $expect";
            note "got : $_";
        }
-       ok($expect eq $_);
+       ok($expect eq $_, $comment // '');
     }
 }
 close $T;
diff --git a/t/win32/system_tests b/t/win32/system_tests
index e2445ed..8307222 100644
--- a/t/win32/system_tests
+++ b/t/win32/system_tests
@@ -87,7 +87,7 @@ my @av = (
   ['" "', 'a" "b" "c', "abc"],
 );
 
-print "1.." . (@commands * @av * 2) . "\n";
+print "1.." . (@commands * @av * 3) . "\n";
 for my $cmds (@commands) {
     for my $args (@av) {
        my @all_args;
@@ -119,5 +119,14 @@ for my $cmds (@commands) {
            }
        }
        $^D = 0;
+
+       note "# pipe [".join(";", @cmds, @args). "]";
+       if (open my $io, "|-", @cmds, @args) {
+           print <$io>;
+           close $io;
+       }
+       else {
+           print "Failed pipe open: $!\n";
+       }
     }
 }
diff --git a/win32/win32.c b/win32/win32.c
index 26d419e..21cdcc6 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -136,6 +136,8 @@ static int  do_spawn2_handles(pTHX_ const char *cmd, int 
exectype,
                         const int *handles);
 static int     do_spawnvp_handles(int mode, const char *cmdname,
                         const char * const *argv, const int *handles);
+static PerlIO * do_popen(const char *mode, const char *command, IV narg,
+                        SV **args);
 static long    find_pid(pTHX_ int pid);
 static void    remove_dead_process(long child);
 static int     terminate_process(DWORD pid, HANDLE process_handle, int sig);
@@ -146,7 +148,7 @@ static char*        wstr_to_str(const wchar_t* wstr);
 static long    filetime_to_clock(PFILETIME ft);
 static BOOL    filetime_from_time(PFILETIME ft, time_t t);
 static char*   create_command_line(char *cname, STRLEN clen,
-                       const char * const *args);
+                                   const char * const *args);
 static char*   qualified_path(const char *cmd);
 static void    ansify_path(void);
 static LRESULT win32_process_message(HWND hwnd, UINT msg,
@@ -2931,22 +2933,13 @@ win32_pipe(int *pfd, unsigned int size, int mode)
 DllExport PerlIO*
 win32_popenlist(const char *mode, IV narg, SV **args)
 {
- Perl_croak_nocontext("List form of pipe open not implemented");
- return NULL;
-}
+    get_shell();
 
-/*
- * a popen() clone that respects PERL5SHELL
- *
- * changed to return PerlIO* rather than FILE * by BKS, 11-11-2000
- */
+    return do_popen(mode, NULL, narg, args);
+}
 
-DllExport PerlIO*
-win32_popen(const char *command, const char *mode)
-{
-#ifdef USE_RTL_POPEN
-    return _popen(command, mode);
-#else
+STATIC PerlIO*
+do_popen(const char *mode, const char *command, IV narg, SV **args) {
     int p[2];
     int handles[3];
     int parent, child;
@@ -2955,6 +2948,7 @@ win32_popen(const char *command, const char *mode)
     int childpid;
     DWORD nhandle;
     int lock_held = 0;
+    const char **args_pvs = NULL;
 
     /* establish which ends read and write */
     if (strchr(mode,'w')) {
@@ -3008,8 +3002,32 @@ win32_popen(const char *command, const char *mode)
     {
        dTHX;
 
-       if ((childpid = do_spawn2_handles(aTHX_ command, EXECF_SPAWN_NOWAIT, 
handles)) == -1)
-           goto cleanup;
+       if (command) {
+           if ((childpid = do_spawn2_handles(aTHX_ command, 
EXECF_SPAWN_NOWAIT, handles)) == -1)
+               goto cleanup;
+
+       }
+       else {
+           int i;
+
+           Newx(args_pvs, narg + 1 + w32_perlshell_items, const char *);
+           SAVEFREEPV(args_pvs);
+           for (i = 0; i < narg; ++i)
+               args_pvs[i] = SvPV_nolen(args[i]);
+           args_pvs[i] = NULL;
+
+           if ((childpid = do_spawnvp_handles(P_NOWAIT, args_pvs[0], args_pvs, 
handles)) == -1) {
+               if (errno == ENOEXEC || errno == ENOENT) {
+                   /* possible shell-builtin, invoke with shell */
+                   Move(args_pvs, args_pvs+w32_perlshell_items, narg+1, const 
char *);
+                   Copy(w32_perlshell_vec, args_pvs, w32_perlshell_items, 
const char *);
+                   if ((childpid = do_spawnvp_handles(P_NOWAIT, args_pvs[0], 
args_pvs, handles)) == -1)
+                       goto cleanup;
+               }
+               else
+                 goto cleanup;
+           }
+       }
 
        win32_close(p[child]);
 
@@ -3028,7 +3046,21 @@ cleanup:
     win32_close(p[1]);
 
     return (NULL);
+}
+
+/*
+ * a popen() clone that respects PERL5SHELL
+ *
+ * changed to return PerlIO* rather than FILE * by BKS, 11-11-2000
+ */
 
+DllExport PerlIO*
+win32_popen(const char *command, const char *mode)
+{
+#ifdef USE_RTL_POPEN
+    return _popen(command, mode);
+#else
+    return do_popen(mode, command, 0, NULL);
 #endif /* USE_RTL_POPEN */
 }
 

--
Perl5 Master Repository

Reply via email to