[erlang-questions] Strange behavior for os:cmd()

Robert Raschke rtrlists@REDACTED
Mon Mar 8 12:01:07 CET 2010


On Sun, Mar 7, 2010 at 8:30 PM, Sergey Yelin <elinsn@REDACTED> wrote:

> Hi there,
>
> Just found os:cmd() gives differend results when I try to execute
> external program by name and by full path. For example,
>
> 1>os:cmd("hg").
> "Mercurial Distributed SCM\n\nbasic commands:\n\n add
> ...
> [SKIP OTHER MERCURIAL HELP OUTPUT]
> "
> 2>  os:find_executable("hg").
> "c:/Program Files (x86)/TortoiseHg/hg.exe"
> 3> os:cmd(os:find_executable("hg")).
> []
> 4> os:cmd("c:/Program Files (x86)/TortoiseHg/hg.exe").
> []
>
> Is this correct behavior or am I missing something?
>
>
Windows quoting is a right pain. Try:

   os:cmd("\""++os:find_executable("hg")++"\"").

>From
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/Cmd.mspx(thee
last paragraph applies):

Processing quotation marks

If you specify /c or /k, cmd processes the remainder of string and quotation
marks are preserved only if all of the following conditions are met:
    You do not use /s.
    You use exactly one set of quotation marks.
    You do not use any special characters within the quotation marks (for
example: &<>( ) @ ^ |).
    You use one or more white-space characters within the quotation marks.
    The string within quotation marks is the name of an executable file.

If the previous conditions are not met, string is processed by examining the
first character to verify whether or not it is an opening quotation mark. If
the first character is an opening quotation mark, it is stripped along with
the closing quotation mark. Any text following the closing quotation marks
is preserved.


Robby


More information about the erlang-questions mailing list