1bru1 has asked for the wisdom of the Perl Monks concerning the following question:

I know there are other things I can call, but either they block the script from continuing, or I don't have the module in my ActivePerl install (64-bit v5.14.2.1402). Really I just don't see why I shouldn't be able to use this call. It is working for some programs that I call, but not for others.

The EXEs that don't work do have one thing in common, and different than the others that do work. That is when they are executed a Windows UAC dialog pops up asking me if I want to allow this "unknown publisher" to make changes. I made them all run "As Administrator" and turned UAC completly off, but neither of those changes helped.

Any ideas? Here is the error I get and the code:

Died at library/OpenWinsBurning/ShortCutter.pm line 143. while executing "::perl::CODE(0x4042cd8)" invoked from within ".f3.b9 invoke" ("uplevel" body line 1) invoked from within "uplevel #0 [list $w invoke]" (procedure "tk::ButtonUp" line 24) invoked from within "tk::ButtonUp .f3.b9" (command bound to event)

--------------------------------------------------------------

sub execute { my $this = shift; ## get ref to calling object my $exitStat = 0; ## This is how you execute another program, and it NOT block the cu +rrent script ## (as opposed to system()). my $proc; Win32::Process::Create( $proc, $this->{mLink}->{'Path'}, "", 0, NORMAL_PRIORITY_CLASS, $this->{mLink}->{'WorkingDirectory'} ) || die $this->errorReport(); return $exitStat; }
  • Comment on Starting up an external program with Win32::Process::Create fails for some, no others?
  • Select or Download Code

Replies are listed 'Best First'.
Re: Starting up an external program with Win32::Process::Create fails for some, no others?
by BrowserUk (Patriarch) on Dec 22, 2011 at 23:06 UTC

    The first thing I would try is using the Windows-only asynchronous form of system:

    system 1, $this->{mLink}->{'Path'};

    If that works, I'd stop there(*).

    If not, then $^E may shed some light on the reason.

    (*)Given that system calls the same underlying API, CreateProcess(), with the additional benefit of having been got right over many versions of Perl, I see no benefit in calling that API directly unless I need access to features not exposed through system.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      Yes, that works! Thanks. I had been using system() before I discovered Create(), but I didn't know there was an async way to use it.

      I'm not sure why I can't get Create() to work. I've tried all kinds of permutations, including what BrowserUk suggested, but nothing happens.

      Any way, the system call is much simpler.

        Yes, that works! ... I've tried all kinds of permutations, including what BrowserUk suggested ...

        Erm. I am he. So ... ? :)


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

Re: Starting up an external program with Win32::Process::Create fails for some, no others?
by GrandFather (Saint) on Dec 22, 2011 at 22:45 UTC

    My Create mantra is a little different to yours. The MSDN documentation is a little confusing regarding the use of the application name and command line parameters used by CreateProcess (which is what Create uses under the hood). I pass the full absolute path including the executable name as the "application name" parameter and I pass what you would likely type on the command line for the command line parameter (generally the executable name sans extension followed by command line parameters). So something like:

    use strict; use warnings; use Win32::Process qw(); my $app = "$ENV{SystemRoot}\\Notepad.exe"; my $cmd = 'Notepad "my file.txt"'; my $proc; my $flags = Win32::Process::NORMAL_PRIORITY_CLASS(); my $startDir = 'c:\\tmp'; Win32::Process::Create($proc, $app, $cmd, 0, $flags, $startDir);

    It may be that providing the full command line for the application name is causing grief in some cases?

    True laziness is hard work
Re: Starting up an external program with Win32::Process::Create fails for some, no others?
by Anonymous Monk on Dec 23, 2011 at 00:30 UTC