问题标签 [getopt-long]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
5178 浏览

c - getopt_long 在哪里存储无法识别的选项?

getoptorgetopt_long遇到非法选项时,它会将有问题的选项字符存储在optopt. 当非法选项是选项时,我在哪里可以找到选项是什么?有没有什么有意义的东西被存储在optopt里面?

我已经设置opterr = 0为禁止自动打印的错误消息。我想创建自己的消息,我可以打印或记录到我想要的位置,但我想包含无法识别的选项的名称。

0 投票
3 回答
11496 浏览

perl - 使用 Getopt 解析 args 时如何允许未定义的选项

如果我有这样的命令行:

我的脚本知道--foo,我希望 Getopt 设置变量$opt_foo,但我对-WHATEVER. 我如何告诉 Getopt 解析出我告诉它的选项,然后在字符串变量或列表中获取其余参数?

一个例子:

然后,发出

0 投票
3 回答
5931 浏览

perl - 如何使用 Getopt::Long 方法?

如果输入命令执行是这样的,我该如何使用Getopt::Long方法:

或者

0 投票
1 回答
157 浏览

c - 是否可以通过 getopt_long 参数列表向后移动?

我想根据是否存在特定参数,委托给几个可能的参数列表之一,大致如下:

我能想到的最好的方法是main()处理所有常见的选项,并决定调用几个函数中的哪一个来处理其余的。

请注意,我不想限制顺序,以便公共选项只能首先出现。

我的问题是,如果我optind在第二次解析参数之前重置为 1 ,则会getopt_long通过将无效字符串传递给段错误strncmp- 所以我想我不应该搞乱 optind。

我有一个谷歌,找不到任何关于是否可以跳过getopt_long参数列表的参考(我知道它是可能的getopt),如果是,我该怎么做?

我宁愿不使用任何非标准库。(语言是纯 c,请不要使用 c++)

0 投票
1 回答
586 浏览

ruby - Ruby GetoptLong 如何解析逗号分隔的参数?

如何在 ruby​​ 中解析以逗号分隔的参数?

例如:

$> Main.rb --xmlid 1,2,3,4,5

我想解析 1,2,3,4,5 并将其存储在一个数组中。

我怎样才能做到这一点?

谢谢。

0 投票
4 回答
216 浏览

perl - 如何验证在 Perl 中使用 Getopt::Long 读取了哪些标志?

脚本文件

  • 所有标志都是可选的。

  • 如果我将脚本称为

    .log在打开它之前,我需要在文件名上附加一个Line a.

  • 为此,我需要知道是否GetOptions将某些内容读入$f1或不读入。

如何才能做到这一点?

0 投票
2 回答
257 浏览

c - Perhaps a pointer problem. Linux program + libpcap + getopt_long() + C language

I'm making a network sniffer for my college project using the libpcap library. Majority of the code works without any problem, however, I'm stuck with the following issue. I've added five command line options using getopt_long() function, but one option doesn't work as expected.

The option is -d (--device_info) and is used to print the I.P address and netmask associated with an interface. It takes one argument, which is the name of the interface for which the information is to be printed.

The necessary portion of the code from the program is attached below. My problem is that even though I'm explicitly assigning the name of the interface to char *device (line 35) and then passing that as an argument to print_device_info() (line 36), when print_device_info() executes, it always executes the if block (line 4) i.e char *device is always equal to NULL in print_device_info() even though I pass it as an argument.

I'm a beginner programmer and this is the first "real" project I'm developing. I guess it's a pointer issue but I'm not sure.

Kindly, also suggest some method to solve it.

Edit: Here I'm posting an edited version of the original program. This edited version is a complete program in itself, so should be sufficient for any future queries.

0 投票
1 回答
26465 浏览

bash - 如何在 bash 中同时支持短选项和长选项?

我想在bash脚本中同时支持短选项和长选项,因此可以:

可能吗?

0 投票
1 回答
1575 浏览

c - 带有重复选项输入的 getopt_long()/getopt()

我刚刚了解了这两个功能。一直在网上搜索以了解它们的用法。发现一件事对解析命令行选项输入非常重要,但没有讨论。

在这种情况下,如果输入了重复的选项,这两个函数都无法处理它。我想知道是否有任何 lib 函数可用于此。

如果我必须自己处理。我认为的方法是将短选项收集到一个数组中并在数组中找到相同的选项。

有什么更好的方法吗?

0 投票
2 回答
1344 浏览

c - 为什么在使用 getopt_long 时结构选项数组需要一个额外的虚拟条目

例如选项数组是:

是为了铺垫吗?