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

I have a perl script running under windows 2k (activestate) which runs the following command:
system "start http://www.foo.com/cgi-bin/foo.cgi?a=2&b=3";
This is invoking the system command to open a browser window to the specified url. The problem is that it only sees the cgi parms up to the first question mark, and the rest are apparently intercepted by the operating system because of the question mark.

Is there a way to get the OS to send the complete url to the browser, perhaps by a technique like url-encoding the question mark?

Replies are listed 'Best First'.
Re: how to url encode at OS level?
by Corion (Patriarch) on Jul 19, 2006 at 13:41 UTC

    The OS and the shell don't know about "url-encoding", but they (like Perl) know about "quoting", except that the quoting rules differ between the shells. Perl's system function can (try to) circumvent the shell if you give it a list of strings instead of one string:

    system 'start', 'http://www.foo.com/cgi-bin/foo.cgi?a=2&b=3';

    Alternatively, you can do the shell quoting yourself:

    system 'start "http://www.foo.com/cgi-bin/foo.cgi?a=2&b=3"';
      thanks for the suggestions. Does it work for you? Unfortunately on my system, the first suggestion still results in the subsequent args getting filtered out and the browser only sees the first parameter. Your 2nd suggestion effectively resulted in only 2nd cmd window being displayed.

        Does it work for you? When I type the following into a command prompt:

        Q:\>start "http://www.foo.com/cgi-bin/foo.cgi?a=2&b=3"

        a new console window opens, with the title http://www.foo.com/cgi-bin/foo.cgi?a=2&b=3 gets opened. This is as designed, as the start command often likely interprets the first argument as the console window title (see the help text as output by help start). OK, I admit, I didn't test it, but you should make sure what you attempt will also give the desired result.

Re: how to url encode at OS level?
by Tanktalus (Canon) on Jul 19, 2006 at 13:44 UTC

    You can avoid the command shell altogether, if start is an exe or com file:

    system (qw[start http://www.foo.com/cgi-bin/foo.cgi?a=2&b=3]);
    But something tells me that start is a built-in to cmd.exe, so you'll still need it. In which case, quotes are your friend:
    system q[start "http://www.foo.com/cgi-bin/foo.cgi?a=2&b=3"];
    Hope that helps.

    Update: D'oh - too slow. :-)

      thanks for the suggestion. Did this work for you? start is a builtin, and your suggestion effectively resulted in only 2nd cmd window being displayed. Am I doing something wrong? I'm on win2k.
Re: how to url encode at OS level?
by gellyfish (Monsignor) on Jul 19, 2006 at 15:28 UTC

    I think you are looking for:

    system 'cmd','/c','start','http://www.foo.com/cgi-bin/foo.cgi?a=2&b=3' +;

    /J\

Re: how to url encode at OS level?
by Jenda (Abbot) on Jul 19, 2006 at 21:44 UTC
Re: how to url encode at OS level?
by ww (Archbishop) on Jul 19, 2006 at 15:12 UTC
    possible misconception here:
    This is invoking the system command to open a browser window to the specified url.

    No, it is invoking the system comment to open a DOS window.