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

klaus.berndl@sdm.de klaus.berndl@sdm.de
Mon Nov 13 04:21:00 GMT 2000


OK, here comes my last version of this way, this avoids all the problems
you have mentioned:

function open-file-with-w32 () {
    erg=""
    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 bat or cmd file
            if [ "$erg" != "bat" ] &&
               [ "$erg" != "BAT" ] &&
               [ "$erg" != "cmd" ] &&
               [ "$erg" != "CMD" ]; then
                # check if this extension is associated with a w32-program
                erg=`cmd /c assoc ".$erg" 2>/dev/null`
                if [ "$erg" != "" ]; then
                    # an associtiation exists therefore this call
                    # should theoretically not produce an error.
                    cmd /c start /b `cygpath -w "$i"` 2>/dev/null
                else
                    # we must start the file with a text editor
                    emacs `cygpath -w "$i"`
                fi
            else
                emacs `cygpath -w "$i"`            
            fi
        fi
    done
    unset erg; }
alias o=open-file-with-w32

Now you can open all filetypes with their associated program and if no
association exists it will be opened with the text editor (here emacs)

Hope this helps,
Klaus

> However, I had to make a tiny change to get it to work on my system, 
> which is Windows 2000 Pro.
> 
> What I had to do is put the "/q" option to CMD.exe first. If you 
> leave it where it is, CMD interprets it as the name of the command to 
> execute (because, I think, it follows the "/c" option).
> 
> I also found that when the association for a particular suffix was 
> unknown, instead of a failure status being returned and my editor 
> being invoked instead, the system's "Open With..." dialog is 
> displayed. Even if you cancel that dialog, the CMD / START 
> combination does not return a non-zero exit status. I don't know how 
> to solve this problem. There was nothing obvious in the HELP output 
> for either CMD or START. If you know how to make this work, I (and 
> probably others) would appreciate hearing what it is.
> 
> If you would, please let the list know about this fix and whatever 
> resolution you have for the "Open With..." dialog issue. Both of the 
> mail servers through which I can send mail are spam-blocked by the 
> Cygnus / RedHat list server (one of the rightly, the other 
> wrongly...).

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



More information about the Cygwin mailing list