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

Hi monks,
I'm working with ActiveStatePerl on XP (coming from NT).
Since I'm using XP, I noticed a different behaviour for the `system` command.

I used the command:
system("start /b $File");
Then perl opened the program with which the fileextention was associated.
eg.:
system("start /b file.html");
=> perl will open default browser and show file.html
But since I'm using XP, there is ALWAYS exact 30 seconds delay before opening the program/file. Someone has an idea why this delay occurs?
ps: if I just open a cmd window and type 'start /b file.html', then there is NO delay.

Replies are listed 'Best First'.
Re: system("start ...") has 30 secs delay
by bofh_of_oz (Hermit) on Jul 08, 2005 at 13:09 UTC
    You can try to see whether it is a browser problem or Perl/something else, by using Notepad to open the file:

    system("c:\\windows\\system32\\notepad.exe file.html");
    and timing that, then comparing to the time with "start"...

    --------------------------------
    An idea is not responsible for the people who believe in it...

      bofh_of_oz,
      I think this idea brings us closer to the problem.
      If I do:
      system("start /b c:\\WINNT\\system32\\notepad.exe $File");
      then notepad opens the file immediately.
      If I use 'system("start /b $File");', then it takes 30 seconds before it even 'starts to open'.
      Does this mean that there is a problem with the fileextention association or with the path?
      Why is it working from the cmd prompt then?
        Well...

        Firstly, I didn't actually mean to use "start" to start Notepad... just do it directly so that no other system programs are involved - less variables in the equation.

        Second, now you can try this:

        system("c:\\program files\\internet explorer\\iexplore.exe $File");
        (note no "start" command here)

        If you still have 30-sec delay, then the problem is in Perl starting IE. You can try starting a different browser to check it further. If not... just use it that way as it will mean that the system uses these 30 seconds to find the application that should be used with this extension.

        --------------------------------
        An idea is not responsible for the people who believe in it...

Re: system("start ...") has 30 secs delay
by chanio (Priest) on Jul 08, 2005 at 20:18 UTC
    You should also try replacing file.html for file.htm and renaming the file.html.- If it starts quicker, then you should reorganize your file extensions. Perhaps cleaning your registry tree with some good program.- You could look at sysinternals or SystemWorks.

    { \ ( ' v ' ) / }
    ( \ _ / ) _ _ _ _ ` ( ) ' _ _ _ _
    ( = ( ^ Y ^ ) = ( _ _ ^ ^ ^ ^
    _ _ _ _ \ _ ( m _ _ _ m ) _ _ _ _ _ _ _ _ _ ) c h i a n o , a l b e r t o
    Wherever I lay my KNOPPIX disk, a new FREE LINUX nation could be established
Re: system("start ...") has 30 secs delay
by yike (Novice) on Jul 09, 2005 at 09:56 UTC
    Last findings:
    I found out now that the delay occurs from the moment I add the line to create new main window for Tk.

    #!/usr/bin/perl use Tk; my $G_MW=MainWindow->new; my $File='d:\\shared\\target\\TTT.html'; system("start /b $File");

    So WITHOUT the ...MainWindow... line => NO problems.
    WITH the ...MainWindow... line => DELAY.

    The kind of file-extention doesn't seem to matter. I have the same behavior for all filetypes (html,htm,txt,log).
Re: system("start ...") has 30 secs delay
by Madams (Pilgrim) on Jul 13, 2005 at 02:19 UTC
    "start" is a feature of cmd.exe.

    Therefore XP/NT/2000 run a cmd.exe session to handle the pathing and associating instead of handling it in kernel.

    Your delay is caused by the startup of cmd.exe. If your load is small, so is your delay.

    (Provided the scheduler doesn't decide to bump a service in ahead of starting your new process)


    "All too often people confuse their being able to think with their actually having done so. A more pernicious mistake does not exist."

    --Moraven Tollo in Michael A. Stackpole's A Secret Atlas

Re: system("start ...") has 30 secs delay
by anonymized user 468275 (Curate) on Jul 08, 2005 at 12:15 UTC
    XP is a descendant of Windows 98 (mainstream consumer Windows) which schedules processes from the active window, whereas the NT kernel was originally built from scratch specifically to enable Windows to compete with the multi-user task scheduling environments offered by rivals such as Unix/X-Windows, (i.e. "real" operating systems built up from carefully designed service layers).

    Your example compares starting a process directly from a DOS window and from the system command in perl. The latter is an example which is more favoured by the NT scheduling module than the XP model, which presumably had to go into contortions to meet this kind of requirement.

    Update: Given that performance anyway varies drastically from one machine environment to another, dependant on many factors, I removed a previous speculation about why it might be 30 seconds.

    One world, one people

      Sorry, but that's completely wrong. Windows XP is built on the Windows 2000 and NT architectures, not based on the Windows 98/95 codebase, although "the best features of Microsoft's consumer operating systems" are apparently merged in.

      Microsoft themselves explain this on their "Features" pages: Home Edition/Professional Edition, and probably in more depth in some KB article or on MSDN somewhere, but I don't have time to go digging.

      Interestingly, a previous employer of mine used to ask the difference between 98 and XP as a part of their interview procedure - it's surprising how many candidates with "Expert: Windows 95/98/Me/2000/XP" on their CV got it wrong ...

      I use the system command from both XP pro and XP home and I never experienced such a behavior.


      holli, /regexed monk/
      A reply falls below the community's threshold of quality. You may see it by logging in.