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

Fellow monks,

I'm trying to launch IE, from a Tk app, to display a local html file using the following code:

my $url = 'C:/Code/Perl/Phi Kap/temp.html'; system "start $url";

but I get a window popping up saying that XP doesn't know how to open file "Phi".

How do I get Perl to pass the entire URL that I've defined in $url so that it all goes through, and doesn't die at Phi? I had thought that wrapping the string in ' ' would cause Perl to evaluate it as an entire string.

Can this be done or is this a problem within XP?

Useless trivia: In the 2004 Las Vegas phone book there are approximately 28 pages of ads for massage, but almost 200 for lawyers.
  • Comment on System command clips off last part of local url when folder name has a space in it
  • Download Code

Replies are listed 'Best First'.
Re: System command clips off last part of local url when folder name has a space in it
by Zaxo (Archbishop) on Aug 16, 2004 at 04:30 UTC

    Use the list form of system,

    my $url = 'C:/Code/Perl/Phi Kap/temp.html'; system 'start', $url;
    That bypasses the shell, so the space doesn't confuse command parsing.

    Alternatively, you could construct the string argument to quote $url after interpolation, probably with qq().

    After Compline,
    Zaxo

      "C:/" is a pretty clear indication of Windows, where this trick doesn't work. Windows programs get a command line passed to them, not a list of command arguments. So you can't bypass the parsing of the command line (even if you bypass the shell). Adding double quotes is usually how to deal with spaces in arguments (for most programs).

      - tye        

Re: System command clips off last part of local url when folder name has a space in it
by davido (Cardinal) on Aug 16, 2004 at 04:26 UTC

    Usually you just have to wrap in shell parsed quotes:

    my $url = '"C:/Code/Perl/Phi Kap/temp.html"'; system "start $url";

    That should do it, as it will pass to the shell the following:

    start "C:/Code/Perl/Phi Kap/temp.html"

    HTH!


    Dave

      No luck. For whatever reason, it opens a command window only in the Phi Kap directory and I get the C:> staring back at me. It won't launch the browser at all.

      Useless trivia: In the 2004 Las Vegas phone book there are approximately 28 pages of ads for massage, but almost 200 for lawyers.

        I'm not sure if this means you haven't solved your problem yet or not. In case it does, this works for me regardless of where the url comes from:

        Update: Corrected typo: s[start][system].

        my $urlWithSpaces = 'C:/Code/Perl/Phi Kap/temp.html'; system qq["$url"];

        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
Re: System command clips off last part of local url when folder name has a space in it
by ikegami (Patriarch) on Aug 16, 2004 at 05:02 UTC
    Alternatively, You could actually put a URL into $url. You won't have that problem since URLs can't have spaces.
    use URI::file; my $path = 'C:/Code/Perl/Phi Kap/temp.html'; my $url = URI::file->new($path)->as_string(); system "start $url";

    Update: Nevermind, this doesn't work. start recognizes the http URI scheme, but not file one (because the HKEY_CLASSES_ROOT\file doesn't have shell\open defined).

Re: System command clips off last part of local url when folder name has a space in it
by PodMaster (Abbot) on Aug 16, 2004 at 07:31 UTC
    I would use HTML::Display

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: System command clips off last part of local url when folder name has a space in it
by tbone1 (Monsignor) on Aug 16, 2004 at 12:26 UTC
    One guess would be that the parser for system does things in the standard Unix way. This will break the command into arguments, using spaces as seperators. This would make the system command break into:

    1) the 'start' command
    2) a first argument 'C:/Code/Perl/Phi'
    3) a second argument 'Kap/temp.html'

    That is why it doesn't know how to open 'Phi', which it sees as a file in the directory 'C:/Code/Perl'.

    --
    tbone1, YAPS (Yet Another Perl Schlub)
    And remember, if he succeeds, so what.
    - Chick McGee