[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] Gawk 4.0.0 Exec's Weirdly
From: |
Eli Zaretskii |
Subject: |
Re: [bug-gawk] Gawk 4.0.0 Exec's Weirdly |
Date: |
Sat, 01 Oct 2011 10:58:02 +0300 |
> Date: Fri, 30 Sep 2011 18:08:19 -0700 (PDT)
> From: David Millis <address@hidden>
> Cc: address@hidden
>
> > From: Eli Zaretskii <address@hidden>
> > Date: Friday, September 30, 2011, 2:48 PM
> >
> > Nothing's changed in Gawk in the code that is involved
> > in running external commands, either via the `system'
> > function or by piping their output to `getline'. In
> > fact, Gawk 3.1.6 that I compiled myself exhibits the
> > same inconsistent behavior that you see in 4.0.0. And
> > I see the same behavior in 3.1.5.
>
> Here's the 3.1.6 build I was using, so you can see what may have been done
> over there (has source).
> http://gnuwin32.sourceforge.net/packages/gawk.htm
>
> Both of these scripts...
> BEGIN {"PAUSE" | getline;}
> BEGIN {system("PAUSE");}
> Show this spawned according to ProcessExplorer: "cmd.exe /c PAUSE"
Exactly what I expected. In the 3.1.6 I compiled from the official
sources, the command in the first case is a single batch file name
whose contents is
@echo off
PAUSE
> I'm not aware of a Windows platform where SHELL is defined by default...
> besides MinGW/Cygwin prompts, which wouldn't point to CMD anyway (so wouldn't
> have the quoting issue to need a tmp.bat).
Some people happen to like having SHELL defined and pointing to a
Unixy shell. At least the Gawk test suite and pc/Makefile.tst expect
you to do that, for the test suite to work.
> It's just that CMD's a goofy interpreter that eats quotes when it sees em in
> its arg.
And using the temporary batch file avoids this idiosyncrasy, even when
SHELL is not set and CMD is used to run the external commands.
> I'll be happy so long as the pipe-loop and system() are consistent with each
> other (with or without the padding). But if an optional env var on one
> platform changes the way commands are executed such that scripts might need
> to check that var too, the mechanism should be documented somewhere.
There will be no change in how commands are executed. If SHELL is set
and points to a Unixy shell name, like "bash", Gawk will produce a
temporary shell script with this content:
bash -c WHATEVER
Otherwise, it will produce a temporary batch file with this:
@echo off
cmd /c WHATEVER
In both cases, the command that is actually run does not need any
special handling or checks by Gawk, and will do what the Gawk script
intended.
> I can argue myself both ways on this. On the one hand, I'm habituated to a
> workaround trivial enough to abandon.
I think having Gawk able to run the same script on Unix as on Windows
is more important that behaving according to old workaround habits. I
hope you will agree.
> On the other, I dislike temp files in general. Fear of adding spaghetti code
> to gawk itself versus slightly tidier scripts.
The tricky code to deal with temporary files is already there, see
popen.c. All I need is to make it work in the `system' case as well;
currently, it only handles pipes, which is why you see inconsistent
behavior.
- Re: [bug-gawk] Gawk 4.0.0 Exec's Weirdly,
Eli Zaretskii <=