【问题标题】:Does cmd.exe enforce syntax rules for command-line utility programs?cmd.exe 是否强制命令行实用程序的语法规则?
【发布时间】:2013-01-18 22:27:32
【问题描述】:

我遇到过几个用 C 或 C++ 编写的命令行实用程序 (CLU) 程序。我见过的所有这些程序都使用减号来控制选项,后跟正在“打开”或“关闭”的名称。例如gdal_translate:

gdal_translate -of GTiff -co "TILED=YES" utm.tif utm_tiled.tif

我的问题:为什么 CLU 程序以这种方式使用减号?这仅仅是被广泛接受为良好实践的东西,CLU 程序在 cmd.exe 中工作所需要的东西,还是 C/C++ 需要的东西?

【问题讨论】:

  • 没有“标准”。很容易解析,我猜。
  • 你正在混合你的环境。 cmd.exe(这是一个shell)在windows中运行,使用/opt的约定,而Unix/linux等也有shell,即bash,ksh,zsh等标准,通过使用函数getopts (和其他方法)是-o -p -t -i -o -n。你可以在windows中编译一个unix命令,你仍然可以使用-o形式。您可以编写自己的本机 Windows cmd,也可以使用 -o 选项。祝你好运。

标签: command-line


【解决方案1】:

我会说更常见的是短/长形式的参数,例如

-C <commit>, --reuse-message=<commit>
    Take an existing commit object, and reuse the log message and the
    authorship information (including the timestamp) when creating the
    commit.

这可能是因为它们可以被getopt_long 解析。就-of 风格而言,这当然是程序员的选择,但我相信需要一个自定义解析器。

ref

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-21
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    • 2021-06-22
    • 2016-12-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多