www.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000310

When Created: 01/01/2000 17:00:07
Against DJGPP version: 2.02
By whom: steve@effectivejava.com
Abstract: system() emulating echo mungs command line
The system() function's emulation of the shell's echo command operates incorrectly. If the text to be echoed contains a combination of + and \ symbols, then the command outputs garbage.

#include <cstdlib>
#include <iostream>

int main()
    const char* p = "echo c:\\dev\\c++\\p13";
    cout << p << '\n';

This produces the output:

echo c:\dev\c++\p13

Other commands lines containing plusses and backslashes, can produce garbage characters instead.

Note added: 01/07/2000 05:00:22
By whom: eliz@is.elta.co.il
I can only reproduce this with GNU `echo' (from GNU Sh-utils package).
So I'm guessing that the person who reported this has GNU Sh-utils installed.
Therefore, this isn't a DJGPP bug.

In fact, it isn't even a bug in GNU `echo', it's a feature!  GNU `echo' by
default interprets escape sequences in the string, unless invoked with the
-E switch.  (Unfortunately, the docs included with Sh-utils 1.12, which was
ported to DJGPP, lies about the default behavior and doesn't mention -E.)

Workaround added: 01/07/2000 05:00:04
By whom: eliz@is.elta.co.il
Several work-arounds:

  1) Rename echo.exe to something else.  Then `system' will invoke the
     internal command ECHO of COMMAND.COM.

  2) Invoke COMMAND.COM explicitly, like this:

     const char *p = "command.com /c echo c:\\dev\\c++\\p13";

  3) Invoke `echo' with the -E switch:

     const char *p = "echo -E c:\\dev\\c++\\p13";

  4) Use forward slashes instead of backslashes:

     const char *p = "echo c:/dev/c++/p13";

Closed on 01/07/2000 05:00:02: This is a feature of GNU `echo', not a DJGPP bug.
By whom: eliz@is.elta.co.il

Note added: 01/07/2000 06:00:17
By whom: eliz@is.elta.co.il
Oh, and by the way: `system' does NOT emulate the echo command.  This feature
is disabled in the sources and was never operational.

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2010   by DJ Delorie     Updated Jul 2010