bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Gawk 4.0.0 Exec's Weirdly


From: David Millis
Subject: Re: [bug-gawk] Gawk 4.0.0 Exec's Weirdly
Date: Fri, 30 Sep 2011 18:08:19 -0700 (PDT)

> 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"

Which is consistent with what Debian (3.1.7) does...
BEGIN{system("sleep 30");}
Shows in ps: "sh -c sleep 30";

> From: Eli Zaretskii <address@hidden>
> Date: Friday, September 30, 2011, 2:48 PM
> > Date: Fri, 30 Sep 2011 17:55:01 +0300
> > From: Eli Zaretskii <address@hidden>
> > 
> > The wrapper code is supposed to cause Gawk heed to the SHELL
> > environment variable.  I'm inclined to change the wrapper so that if
> > SHELL is not defined in the environment, it does nothing and calls the
> > original `popen' from the C library with the original command.  If no
> > one objects, I will do it when I have time.
> 
> On second thought, perhaps instead of bypassing the wrapper,
> I should enable a similar wrapper around the call to 'system',
> in which case both your "System" and "Loop" methods will no
> longer need extra quoting.  WDYT?

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).

It's just that CMD's a goofy interpreter that eats quotes when it sees em in 
its arg. As I mentioned, other languages (since they simply pass an arg to 
COMSPEC) leave it to the programmer to deal with quote-padding.

command = "...";
command = stupidQuotes(command); # Optionally a platform check here :)
system(command);

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.

I can argue myself both ways on this. On the one hand, I'm habituated to a 
workaround trivial enough to abandon. On the other, I dislike temp files in 
general. Fear of adding spaghetti code to gawk itself versus slightly tidier 
scripts.


David Millis




reply via email to

[Prev in Thread] Current Thread [Next in Thread]