develooper Front page | perl.perl5.porters | Postings from May 2004

Re: Problem with system() on Win9x and command.com (perl5.8.x-5.9.x)

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
May 5, 2004 04:41
Subject:
Re: Problem with system() on Win9x and command.com (perl5.8.x-5.9.x)
Message ID:
20040505133836.089083b7@localhost
bilbo@ua.fm wrote:
>   I have problem with perl 5.8.x-5.9.x on Windows98SE (Win9x). When I
>   run some executable via system() - all work ok. But when I try to
>   run .bat file with system(), .bat file does not receive command line
>   parameters.
[...]
> I also found source of this bug, in file win32/win32.c:
> 
>     /* The NT cmd.exe shell has the following peculiarity that needs to be
>      * worked around.  It strips a leading and trailing dquote when any
>      * of the following is true:
>      *    1. the /S switch was used
>      *    2. there are more than two dquotes
>      *    3. there is a special character from this set: &<>()@^|
>      *    4. no whitespace characters within the two dquotes
>      *    5. string between two dquotes isn't an executable file
> >     * To work around this, we always add a leading and trailing dquote
> >     * to the string, if the first argument is either "cmd.exe" or "cmd",
> >     * and there were at least two or more arguments passed to cmd.exe
> >     * (not including switches).
>      * XXX the above rules (from "cmd /?") don't seem to be applied
>      * always, making for the convolutions below :-(
>      */
> 
> Because of this, system('test_bat.bat 1 2 3 4 5 6 7 8 9') really run
> '"test_bat.bat 1 2 3 4 5 6 7 8 9"', and command.com can't understand this.
> 
> I make patch for this bug.
> 
> --- win32/win32.c       Wed Feb 04 04:22:18 2004
> +++ win32/win32.c       Sat Apr 17 15:02:42 2004
> @@ -3538,11 +3538,12 @@
>         if (clen > 4
>             && (stricmp(&cname[clen-4], ".bat") == 0
>                 || (IsWinNT() && stricmp(&cname[clen-4], ".cmd") == 0)))
>         {
>             bat_file = TRUE;
> -           len += 3;
> +           if (!IsWin95())
> +               len += 3;

Sorry for haven't answering to this earlier, but I'm a bit uncomfortable
to rely on the operating system version to determine which command shell
is used. Couldn't you instead look at the shell name? (I haven't any
Win32 machine to test.)

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About