Skip to content

Conversation

@nrdvana
Copy link
Contributor

@nrdvana nrdvana commented Nov 3, 2019

The Win32 CreateProcess call allows the application name or cmdline arguments to be NULL. Allowing application name to be NULL is the only way to ask Win32 to search the PATH for the executable named in the commandline argument. This is a very useful behavior and would avoid effort in various modules like Proc::Background to have to resolve the executable name by manually searching the PATH.

erco77 and others added 2 commits November 3, 2019 14:20
Date: 	Wed, 27 Dec 2006 03:55:22 -0800
To: 	bug-libwin32@rt.cpan.org
From: 	Greg Ercolano <erco@seriss.com>

OK, after reading perlguts and perlxs (woof) I think I get it.

The right approach might be to allow 'undef' on the perl side
to be used where NULL would be needed on the C side to pass to
CreateProcess().

So it seems the simple solution might be to make this simple two line
change to Process.xs:

```
--- Process/Process.xs  2005-09-17 12:36:38.000000000 -0700
+++ Process/Process.xs.erco     2006-12-27 03:19:29.000000000 -0800
@@ -283,6 +283,8 @@
      DWORD flags
      char *curdir
  CODE:
+    appname = SvOK(ST(1)) ? appname : 0;
+    cmdline = SvOK(ST(2)) ? cmdline : 0;
      RETVAL = Create(cP, appname, cmdline, inherit, flags, curdir);
  OUTPUT:
      cP
```

..which then makes this work correctly:

    Process::Create($pobj, undef, "netstat -an", 1, NORMAL_PRIORITY_CLASS, ".");

The docs should cover this, so I've included some recommended text
Slightly different implementation of previous.
Let perl give us the SV, then decide whether to call
SvPV on it based on whether it is defined.
@iynehz
Copy link

iynehz commented May 2, 2021

@jandubois Can we get this PR merged and cut a new version? We're looking at an IPC::Run issue cpan-authors/IPC-Run#143 (comment) and I think that one can have a decent fix if we support NULL for appname in Win32::Process::Create()

@jandubois jandubois merged commit 7f19fda into jandubois:master May 13, 2021
@jandubois
Copy link
Owner

@stphnlyd I've just uploaded Win32-Process-0.17 to CPAN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants