avoiding escaping chars in exec commands

From: Tennis Smith (tennis_smith_at_yahoo.com)
Date: 10/31/03

  • Next message: bitCrypT: "entry widgets and tabbing"
    Date: 30 Oct 2003 17:47:17 -0800
    
    

    Hi,

    I sometimes have to do relatively complex interactions with other
    tools inside tcl. They are accessed using "exec".

    But, often the tools being used have chars in the invocation which are
    special to tcl. So far, I simply escape the chars with a "\".

    That works, but causes some pretty ugly source code. For example, if
    I want to do something like this from tcl:

    awk '/cmd=/ { printf("%s %s %s %s", $1,$2,$8,$7); for (i = 14; i < NF;
    i++) printf( " %s",$i); print "" }' aaa_raw > blit

    I have to make it look like this in the source file code fragment:

    if [catch {exec /usr/bin/sh -c \
                   "awk '/cmd=/ \
                   { printf(\"%s %s %s %s\", \$1,\$2,\$8,\$7); \
                     for (i = 14; i < NF; i++) printf( \" %s\",\$i); \
                     print \"\" \
                   }' $raw_file > $raw2_file" \
               } err] {
        puts stderr "CapAAA-003: $err"
        exit 0
    }

    Is there any way to avoid using the "\" char everywhere and passing
    the whole thing at once?

    TIA,
    -Tennis


  • Next message: bitCrypT: "entry widgets and tabbing"

    Relevant Pages

    • Re: How to convert a string (words between random spaces) in to a tcl list?
      ... $str can be interpreted as a list with no further effort: ... if the string isn't in the form ... of a Tcl list, no amount of magic could possibly turn it into a list. ... confusing to make an exception in the case of whitespace chars. ...
      (comp.lang.tcl)
    • Re: So slow Tcl :(
      ... Take the first X characters of each string in a record (we'll call ... since some unicode chars take up more than ... but most benchmarks do not include the fields where Tcl is good. ...
      (comp.lang.tcl)
    • Re: tcl and C
      ... Some remarks: ... In cases like these I usually let TCL do the job of counting the ... chars, ...
      (comp.lang.tcl)
    • Re: Q: How to determine if a process has been terminated
      ... parent process you get the pid returned from the fork call; ... any pid and delete it from the list, ... calls to exec (which is actually called "system" in the C/ APUE ... There seems to be no set of corresponding commands in Tcl though. ...
      (comp.lang.tcl)
    • Re: Problem in calling c programs and compiling them in tcl/tk
      ... using exec gcc filename.c and later exec ./a.out filename.c. ... use their exit status for abnormal exits, and that has spoilt the Tcl ... If the "single worst design mistake in Tcl" is really something with a trivial 1-line fix, then Tcl must surely be perfection! ...
      (comp.lang.tcl)