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

Dearest Monks,
I've never really had much experience with windows IIS, and I'm trying to run this painfully simple script
#!c:/Perl/bin/perl.exe print "Content-type: text/html\n\n"; print "Created Installer 2: "; my $value = system(1,'c:\program\ie\makeinstall 2'); #my $value = system(1,'c:\program\ie\makeinstall.bat 2'); print "value=$value";

The output: Created Installer 2: value=-1

Anything glaringly wrong with this syntax? I've also used the exec statement in place of statement. Seeking the Monks infinite wisdom

UPDATE: I changed the permissions, however this is the output now: Created Installer 2: value=65280 and there was no installer creation (the point of the batch file)

UPADATE2: Also if I double click on the pl file, the script runs fine and builds the installer. I'm not sure what new permissions I can give to the folder that its running in, it has every single one open.

Replies are listed 'Best First'.
Re: Executing windows batch files via System
by BrowserUk (Patriarch) on Apr 26, 2007 at 00:01 UTC

    This is almost certainly a "permissions thing".

    By default, webservers run under accounts that have severely restricted permissions, which is probably preventing the script from working.

    Beyond that, allowing people to invoke a script on your server, via a web page seems like a really dumb idea to me.


    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.

      I agree. Anyway, what the DOS batch file is doing anyway? I doubt you couldn't rewrite the functionality (even if you're going to use system()) in some parts) using Perl code.

      If you're using ActivePerl, my suggestion is that you take a look at the module Win32::Process and see if it's not a better option for the problem.

      Alceu Rodrigues de Freitas Junior
      ---------------------------------
      "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill

        What makes you think that using Win32::Process will make the slightest bit of difference?

        1. system 1, ... maps directly to the api CreateProcess() which is exactly what Win32::Process does.
        2. If the batch file fails when run under ther web server account, trying to do those same things, from within perl under the web server account, will fail also.

        Perl cannot solve permissions problems without correcting the permissions problem, and once you have done that, the batch file would work anyway, without needing to try re-write it in perl.


        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.
Re: Executing windows batch files via System
by ikegami (Patriarch) on Apr 25, 2007 at 23:46 UTC

    Does it work when you run the script from a Console prompt? I don't have any problems running a batch file using system:

    >copy con batch.bat @echo off echo Running! ^Z 1 file(s) copied. >perl -e"system 'batch.bat'" Running!

    If it runs from the prompt, then it's likely to be a permission problem (since the script is surely being run as another user) or an access problem (from running as a service).

    By the way, running the the kid asynchronously seems peculiar in this situation. I think system(1, ...) should be system(...) in this case.

      Thanks for your input, I changed the permissions and instead of getting the -1 output from system I get the value 65280, but the batch file doesn't create the installer in which is the point of the batch file
Re: Executing windows batch files via System
by c4onastick (Friar) on Apr 25, 2007 at 22:48 UTC
    From perldoc on system:
    "if LIST is an array with more than one value, starts the program given by the first element of the list with arguments given by the rest of the list."

    I've never used system in this syntax (using the return value) but it looks like its just running the program "1" and passing everything else as an argument. Try this:
    #!c:/Perl/bin/perl.exe print "Content-type: text/html\n\n"; print "Created Installer 2: "; system('c:\program\ie\makeinstall', '2');
      system(1, ...) is a Windows feature to run a program asynchronously. Kinda like fork+exec for a system without fork.
        Ah, interesting to know. See, you learn something new everyday!