getopt

option followed by a option in getopt [where the earlier option was expecting a value]

谁都会走 提交于 2019-12-13 01:04:58
问题 I have a doubt if we have two option -a and -c and option -a needs to have a value and no value for -c now if i give ->testopt -a -c [testopt is program] then my program takes -c as a value for -a . is there a way where i can make sure that a option with value does not have other options as its values ? the thing is that the system accepts - one keyword's value as another keyword which i need to prevent . e.g. - testopt -a -c. in this case there was a mandatory argument (value ) for -a and no

Why isn't getopt working if sys.argv is passed fully?

那年仲夏 提交于 2019-12-12 10:53:45
问题 If I'm using this with getopt : import getopt import sys opts,args = getopt.getopt(sys.argv,"a:bc") print opts print args opts will be empty. No tuples will be created. If however, I'll use sys.argv[1:] , everything works as expected. I don't understand why that is. Anyone care to explain? 回答1: The first element of sys.argv ( sys.argv[0] ) is the name of the script currently being executed. Because this script name is (likely) not a valid argument (and probably doesn't begin with a - or --

Using getopt in C for command line arguments

僤鯓⒐⒋嵵緔 提交于 2019-12-12 06:03:32
问题 I am working on trying to take in command line arguments. If I want to have multiple optional command line arguments how would I go about doing that? For example you can run the program in the following ways: (a is required every instance but -b -c -d can be given optionally and in any order) ./myprogram -a ./myprogram -a -c -d ./myprogram -a -d -b I know that getopt()'s third argument is options. I can set these options to be "abc" but will the way I have my switch case set up causes the

How to use getopt with this several values?

吃可爱长大的小学妹 提交于 2019-12-11 18:53:56
问题 I try to achieve a script with multi options. I started with the doc, get some errors, went to the browser. Read some links and find this on SO : Using getopts in bash shell script to get long and short command line options. So I read it and rewrote my script. I made a mistake somewhere. Where am I wrong ? SH #!/bin/sh TEMP=`getopt -o vfts: --long verbose,format,type,style: \ -n 'opt2' -- "$@"` if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi eval set -- "$TEMP" VERBOSE=false

getopt erroneously caches arguments

放肆的年华 提交于 2019-12-11 16:15:26
问题 I've created a script in my bash_aliases to make SSH'ing onto servers easier. However, I'm getting some odd behavior that I don't understand. The below script works as you'd expect, except for when it's re-used. If I use it like this for this first time in a shell, it works exactly as expected: $>sdev -s myservername ssh -i ~/.ssh/id_rsa currentuser@myservername.devdomain.com However, if I run that a second time, without specifying -s|--server , it will use the server name from the last time

Build failure during install py25-gtk on Mac OS X 10.6 using MacPorts 1.8

天大地大妈咪最大 提交于 2019-12-11 13:27:27
问题 When I do this command : sudo port clean py25-gtk sudo port install py25-gtk I get this error : ---> Computing dependencies for py25-gtk ---> Building getopt Error: Target org.macports.build returned: shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_sysutils_getopt/work/getopt-1.1.4" && /usr/bin/make -j2 all LIBCGETOPT=0 prefix=/opt/local mandir=/opt/local/share/man CC=/usr/bin/gcc-4.2 " returned error 2 Command output: _print

getopt error handling for multiple comma separated values

我的未来我决定 提交于 2019-12-11 06:04:50
问题 how to validate a string variable for multiple combinations of comma separated values received from command line for getopt? case 'a' : flaga=1; alg = optarg; printf("you entered option -a \"%s\"\n", optarg); if(strcmp(alg,"lr") == 0 ) { ....//valid } else if(strcmp(alg,"lda") == 0 ) { ....//valid } else if(strcmp(alg,"knn") == 0 ) { ...//valid } """"" """" else { printf("wrong value entered for option -a \n"); exit(); } option -a can accept these values : "knn","lda","lr","kart","nb","svm" .

How to prevent getopt from being confused with option with missing argument?

蓝咒 提交于 2019-12-11 05:27:19
问题 Say, I have code: while ((c = getopt(argc, argv, ":n:p")) != -1) { switch (c) { case 'n': syslog(LOG_NOTICE, "n: %s", optarg); break; case 'p': /* ... some code ... */ break; case ':': /* handle missing arguments to options requiring arguments */ break; /* some cases like '?', ... */ default: abort(); } } When I call my program as ./main -n -p it prints: n: -p Why does not getopt return : to indicate that argument to -n is missing but instead uses -p as parameter argument? 回答1: It is

WINDOWS VS2019有关getopt及getopt_long的问题

…衆ロ難τιáo~ 提交于 2019-12-11 04:49:38
先吐槽一下,VS真的有时候很讨厌,特别是某些linux下才有的库,要想在windows,vs调试成功,真的不容易,还要考虑vs版本不同可能带来的麻烦,谁知道,还是得多试试,以及多点耐心。 我的是win10,vs2019 我的项目中,需要引入unistd.h头文件,vs没有(对,它没有!)然后需要自己写一个资源里有 另外资源中的三个getopt有关压缩包都是可以用的,任意解压一个复制当中的getopt.h及getopt.c直接添加到自己项目的相应位置就可以了。 来源: CSDN 作者: zrkl100 链接: https://blog.csdn.net/zrkl100/article/details/103465474

getopt for Visual Studio CRT?

醉酒当歌 提交于 2019-12-11 04:21:51
问题 Is there an equivalent to getopt() in the visual studio CRT? Or do I need to get it and compile it with my project? Edit clarification getopt is a utility function in the unix/linux C Run Time library for common command line parsing chores i.e. parsing arguments of the form -a -b -f someArg etc' 回答1: You can use the getopt implementation from the GNU C library. It's licensed under the LGPL, which should be compatible with most software projects. See the file posix/getopt.c in the source