Problem executing a .bat script in a directory with spaces using bash

Christopher Cobb ccobb@email.com
Fri Sep 3 14:43:00 GMT 2004


Igor Pechtchanski <pechtcha <at> cs.nyu.edu> writes:
> I believe you're missing the point.  Try
> 
> ./test.bat "hello world"
> 
> and you'll get the error.

I use the following shell function cmd() to invoke batch files.  It removes
cygwinisms from the PATH and the environment first and does some argument
pre-processing.  It also seems to fix the space problem.

chcobb@CHCOBB-054009 /c/Documents and Settings 10:36:09
508$ cat test.bat
echo %1

chcobb@CHCOBB-054009 /c/Documents and Settings 10:38:30
509$ cmd test "Hello, world."

C:\Documents and Settings>echo "Hello, world." 
"Hello, world."


--- cmd() ---
cmd () 
{ 
    ( local c="`cygpath -w \"$1\"`";
    shift;
    local cmd=`cygpath -u $COMSPEC`;
    while [ $# != 0 ]; do
        if [ -f "$1" ]; then
            local args="$args '`cygpath -w $1`'";
        else
            if [ -d "$1" ]; then
                local args="$args '`cygpath -w $1 | sed 's@\\\\\$@@'`'";
            else
                local args="$args '$1'";
            fi;
        fi;
        shift;
    done;
    PATH=`echo $PATH |
          tr : '\n' |
          egrep -vw '^(/usr/local/bin|/usr/bin|/bin|/usr/X11R6/bin)$' |
          tr '\n' :`;
    unset BASH_ENV COLORTERM CYGWIN DISPLAY HISTCONTROL MAKE_MODE;
    unset MANPATH PKG_CONFIG_PATH PS1 PWD SHLVL TERM USER _;
    unset CVS CVSROOT CVS_RSH GEN_HOME GROOVY_HOME TOMCAT_DIR;
    eval $cmd /c "$c" $args )
}
--- end cmd() ---



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list