AW: Ultimative way to start Windows NT/2000 programs from bash

klaus.berndl@sdm.de klaus.berndl@sdm.de
Mon Nov 13 06:09:00 GMT 2000


> My be you should remove now 95 and 98 from the subject <g>. 

Has been done.

> What about other
> executables or script files identified by PATHEXT ?

Yes, good point! here is the next iteration (the last one i hope :-)

# open any file in the correct program: an associated file-type (see assoc
# and ftype at Windows NT/2000) will be opened with the associated program.
# Not associated filetypes and files which extension is contained in
# $PATHEXT will be opened in the texteditor (here Emacs). Files with
# extension .exe and .com will not be opened!

function open-file-with-w32 () {
    for i in $*; do
        if [ -f "$i" ]; then
            # get the extension only
            erg=`echo $i | sed -e 's|.*\.||g;'`
            # check if we try to open a program
            if [ "$erg" != "exe" ] &&
               [ "$erg" != "EXE" ] &&
               [ "$erg" != "com" ] &&
               [ "$erg" != "COM" ]; then
                # check if we try to open a file with a extension from $PATHEXT
                is_path_ext=`echo "$PATHEXT"\; | grep -i "\.$erg;"`
                if [ "$is_path_ext" == "" ]; then
                    # check if this extension is associated with a w32-program
                    erg=`cmd /x /c assoc ".$erg" 2>/dev/null`
                    if [ "$erg" != "" ]; then
                        # an associtiation exists therefore this call should
                        # theoretically not produce amn error.
                        cmd /x /c start /b `cygpath -w "$i"` 2>/dev/null
                    else
                        # we must open the file with a text editor because
                        # it is not associated.
                        emacs `cygpath -w "$i"`
                    fi
                else
                    # files with a extension contained in $PATHEXT will be
                    # opened with the text editor.
                    emacs `cygpath -w "$i"`            
                fi
            else
                echo "$i is a program!"
            fi
        fi
    done
    unset erg is_path_ext; }
alias o=open-file-with-w32

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com



More information about the Cygwin mailing list