I want to execute a windows program in cygwin console. I have tried various forms but I don't find the correct syntax.

 $ cmd /C "C:\Program Files\sqldeveloper\sqldeveloper\bin\sdcli.exe format input=sentencia.tmp output=sent_formateada.tmp"
    "C:\Program" no se reconoce como un comando interno o externo,
    programa o archivo por lotes ejecutable.

 $ cmd /C "C:\Program Files\sqldeveloper\sqldeveloper\bin\sdcli.exe" format input=sentencia.tmp output=sent_formateada.tmp
        format input=<archivo o directorio de entrada> output=<archivo o directorio de salida>

 $ cmd /C C:\\"Program Files"\\sqldeveloper\\sqldeveloper\\bin\\sdcli.exe format input=o:\\Mezcla\\Scripts\\Oracle\\Informes_HTML\\TMP\\sentencia.tmp output=o:\\Mezcla\\S cripts\\Oracle\\Informes_HTML\\TMP\\sent_formateada.tmp

    Error en input=o:\Mezcla\Scripts\Oracle\Informes_HTML\TMP\sentencia.tmp output=o:\Mezcla\Scripts\Oracle\Informes_HTML\TMP\sent_formateada.tmp
    format input=<archivo o directorio de entrada> output=<archivo o directorio de salida>
    Comando terminado.

Why are you invoking cmd? That's an extra level of complexity that you don't seem to need. You can invoke the Windows program directly from bash:

'C:\Program Files\sqldeveloper\sqldeveloper\bin\sdcli.exe' format input=sentencia.tmp output=sent_formateada.tmp


/cygdrive/c/Program\ Files/sqldeveloper/sqldeveloper/bin/sdcli.exe format input=sentencia.tmp output=sent_formateada.tmp

or any other way of quoting in sh.

If you must invoke cmd, you may need to pass the cmd code on standard input or in a batch file rather than with /c, because /c parses quotes in a different way (which doesn't make sense to me). That would be

cmd <<<'"C:\Program Files\sqldeveloper\sqldeveloper\bin\sdcli.exe" format input=sentencia.tmp output=sent_formateada.tmp'
  • The two examples without cmd it doesn't find the sdcli.exe program $ 'C:\Program Files\sqldeveloper\sqldeveloper\bin\sdcli.exe' format input=o:\informes\sentencia.tmp output=o:\Informes\sent_formateada.tmp sh: C:\Program Files\sqldeveloper\sqldeveloper\bin\sdcli.exe: no se encontró la orden – estonolose May 28 '17 at 1:06
  • The cmd works when I execute in cygwin, but if I put this sentence in a .sql script with hosts command it open a cmd but the script stops in cmd session. --- host cmd <<<'"C:\Program Files\sqldeveloper\sqldeveloper\bin\sdcli.exe" format input=o:\Informes\sentencia.tmp output=o:\Informes\sent_formateada.tmp' – estonolose May 28 '17 at 1:15
  • @estonolose <<< is bash syntax, and it passes data to cmd on standard input. I don't know what your .sql scripts are (not SQL scripts, apparently), so I can't offer help here. I don't know why you can't invoke the program directly from the Cygwin shell, your command looks correct to me. Try putting the command in a .bat file. – Gilles May 28 '17 at 1:27

As the other answer indicates you should be able to run the command directly from Cygwin bash prompt. But if you're passing file/dir arguments, native windows programs will expect a native windows path. Rather than attempt to construct such a path by hand you can use the cygpath tool:

# Emits, for example,  'C:\Program Files\MyApp\MyApp.exe'
cygpath --windows '/cygdrive/c/Program Files/MyApp/MyApp.exe'

Another potential pitfall to be aware of is you may have different values between Windows and Cygwin for certain common environment variables such as HOME or TEMP. This isn't as common a problem but if you suspect this may be the case pass the Windows definition(s) ahead of the command. That will launch the program with an environment containing the overridden value. For example, TEMP is /tmp in Cygwin but quite different in Windows so if this was causing problems you might end up with something like:

TEMP="$LOCALAPPDATA\\Temp" MyApp.exe foo bar ...

Finally, be sure to quote any arguments that have spaces embedded in them.

As a side note, I have some wrapper scripts that are aliased to certain Windows programs that allow me to enter Cygwin style args. The wrappers and then use something like this function to convert the args into Windows ready format before passing them to the native app:

# Process positional params, converting file path to Windows format
# and adding quotes around other params if they contain spaces. Result
# saved in array named WINFILEARGS. Call Windows app with single
# arg "${WINFILEARGS[@]}"
make_win_file_args() {
    declare -ga WINFILEARGS

    local SPACEREGEX="[[:alnum:]]+[[:space:]]+[[:alnum:]]+"
    local index=0
    for posparam ; do
        if [[ -e $currparam ]]; then
            # Convert unix paths from command line to windows paths
            currparam="\"$(cygpath -w "${posparam}")\""
        elif [[ $currparam =~ $SPACEREGEX ]]; then
            # Quote non-file parameters that contain spaces
        (( index=$index+1 ))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.