gpt4 book ai didi

java - 如何在 getopt 类中将连字符作为选项参数

转载 作者:行者123 更新时间:2023-11-30 11:28:08 24 4
gpt4 key购买 nike

我必须在

中给出“-”作为选项参数

Getopt class

下面是我的代码

Getopt g = new Getopt("cm_log_parser", args, "i:s"); //-D to enable debug log


while((opt = g.getopt()) != -1)
{
switch (opt)
{
case 'f'://To set file name(if above is not specified)
fileNameWithPath = getAndCheckOptArg(fFlag, opt, g);
fFlag = true;
break;

case 's'://To set the header
String separator = getAndCheckOptArg(hFlag, opt, g);
hFlag = true;
breakk;
case '?':
usage("Invalid option" + opt + " option");
break;
}
}

我想在参数中给出 -s "-"但它显示一些错误,例如无效选项,有什么办法可以做到吗?

最佳答案

--Getopt有特殊意义

The user can force getopt() to stop scanning the command line with the special argument "--" by itself. Any elements occuring before the "--" are scanned and permuted as normal. Any elements after the "--" are returned as is as non-option argv elements. For example, "foo -a -- bar -d" would return option 'a' then -1. optind would point to "foo", "bar" and "-d" as the non-option argv elements. The "--" is discarded by getopt().

所以恐怕你无法完成。

关于java - 如何在 getopt 类中将连字符作为选项参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19007174/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com