command line - running programs from MSYS with quotes

07
2014-07
  • x-yuri

    I'm trying to execute non-MSYS program from within MSYS. But MSYS (bash) doesn't work as expected. I'm running commands and see what procmon has to say about command line passed:

    >cmd /c ""cmd" /c echo test"   &:: procmon says: cmd  /c ""cmd" /c echo test"
    
    $ cmd //c ""cmd" /c echo test"   # procmon says: c:\Windows\system32\cmd.exe /c "cmd /c echo test"
    
    $ cmd //c "\"cmd\" /c echo test"   # procmon says: c:\Windows\system32\cmd.exe /c "\"cmd\" /c echo test"
    

    The question is how to make it pass the exact same arguments cmd passes?

    UPD I want to run hstart from msys bash. But for complex commands hstart expect to see command line like this:

    hstart ""c:\path to\some\command" "d:\some other\path""
    

    I can do this just fine from cmd, but not from msys bash. If I execute it this way:

    $ hstart ""c:\path to\some\command" "d:\some other\path""
    

    the command line turns out to be: hstart c:\path "to\some\command d:\some" other\path Which is not what I suppose it to be. How can I remedy this?

    P.S. I've already got an answer to this.

  • Answers
    Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

    Related Question

    path - How do I stop MSYS from transforming my compiler options?
  • Carl Norum

    Is there a way to stop MSYS/MinGW from transforming what it thinks are paths on my command lines? I have a project that's using nmake & Microsoft Visual Studio 2003 (yeecccch). I have the build system all ported and ready to go for GNU make (and tested with Cygwin). Something weird is happening to my compiler flags when I try to compile in an MSYS environment, though. Here's a simplified example:

    $ cl /nologo
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.6030 for 80x86
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    /out:nologo.exe
    C:/msys/1.0/nologo
    LINK : fatal error LNK1181: cannot open input file 'C:/msys/1.0/nologo.obj'
    

    As you can see, MSYS is transforming the /nologo compiler switch into a windows path, and then sending that to the compiler. I really don't want this to happen - in fact I'd be happy if MSYS never transformed any paths - my build system had to take care of all that when I first ported to Cygwin. Is there a way to make that happen?

    It does work to change the command to

    $ cl -nologo
    

    Which produces the expected results, but this build system is very large and very painful to update. I really don't want to have to go in and change every use of a / for a flag to a -. In particular, there may be tools that don't support the use of the - at all, and then I'll really be stuck.

    Thanks for any suggestions!


  • Related Answers
  • actf

    I found this question while searching for a way to run a windows program which requires an argument in the form:

    /arg:<path>
    

    where path must be a fully qualified windows path

    I just wanted to elaborate on the following from the original question:

    It does work to change the command to

    cl -nologo
    

    Which produces the expected results .... In particular, there may be tools that don't support the use of the - at all, and then I'll really be stuck.

    As the original poster suggests, transforming the argument using - as follows, works perfectly:

    -arg:<path>
    

    I was actually really surprised by this, as this is not documented by the program's help. It just so happens the program in this case is also made by Microsoft (as is nmake in the original poster's case). So if the program you're attempting to run is made by Microsoft give this a shot even if it's undocumented.

    Hopefully there aren't any programs out there that use this (imho insane) form of command line arguments outside of Microsoft, if there are, I don't think it's possible to run them with MSYS

  • Carl Norum

    The final answer is that there is fact no way to stop this behaviour. I had to go through every line in the build system and change every / into a -.