bug-gawk
[Top][All Lists]
Advanced

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

[bug-gawk] Percent Signs in External Commands on Windows


From: David Millis
Subject: [bug-gawk] Percent Signs in External Commands on Windows
Date: Mon, 9 Apr 2012 05:58:36 -0700 (PDT)

BACKGROUND:
Canonical builds had treated loop and system calls inconsistently (one with CMD 
/C, the other with a batch), since 3.1.5.
The GnuWin32 3.1.6 build, in both cases, spawned a CMD /C WHATEVER process, 
where WHATEVER needed to be wrapped in quotes by users for CMD to 
idiosyncratically munch on.


Last fall, there was a thread entitled "Gawk 4.0.0 Exec's Weirdly" where it was 
decided that loop and system calls would both use a temporary batch file when 
SHELL is not defined as something unixy.
---
@echo off
THE EXACT STRING GIVEN TO EXECUTE
---
The benefit was that quotes didn't need to be added because CMD /C isn't 
invoked directly against the string.


PROBLEM:
A sideeffect of using an intermediary script is that percent signs get munched 
on instead... as CMD parses in batch-mode. Any percent followed by a digit, or 
word bounded between two percent signs that wasn't an ENV VAR is replaced with 
an empty value. When passed as an arg, these would've been literals.

---
BEGIN {
  command = "ECHO x%1x";
  system(command);
}
---

Direct libc exec... (tested with python's os.execl)
---
CMD /C "ECHO x%1x"
---
Prints: x%1x

A batch...
---
@echo off
ECHO x%1x
---
Prints: xx


In hindsight, I think GnuWin32 took the less problematic route.
It's much trickier to selectively escape certain percents by doubling them up 
than to concatenate a leading and trailing quote to the whole string.

Technically this has been a problem in official sources since 3.1.5, so you 
might just consider this grandfathered-in expected behavior.

Building on the above examples, I've attached boilerplate funcs to get 
consistent shell execution across various gawk interpreter builds on windows.


David Millis

Attachment: gawk_shellexec.txt
Description: Text document


reply via email to

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