试了一下getopt,代码如下:
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char** argv) {
int c;
char * filename = NULL;
char * input_path = NULL;
char * output_path = NULL;
bool each_by_line = false;
while((c=getopt(argc,argv,"lf:i:o:")) != -1){
switch(c){
case 'f':
filename = optarg;
break;
case 'i':
input_path = optarg;
break;
case 'o':
output_path = optarg;
break;
case 'l':
each_by_line = true;
}
}
if(each_by_line){
printf("process one line each time\n");
}else if(filename != NULL){
if(input_path == NULL || output_path == NULL){
fprintf(stderr,"if filename is set, the input_path and output_path should be set,too\n");
exit(1);
}
printf("process one file each time\n");
printf("filename:%s,input_path:%s,output_path:%s\n",filename,input_path,output_path);
}else{
printf("process by default\n");
}
return 0;
}
分享到:
相关推荐
getopt命令用于解析命令行选项,检测给定的选项是否合法。在此命令中,选项部分主要用于影响getopt命令解析选项,其中optstring是...检查提供的参数列表(-a -b test1 -cd test2 test3),并基于提供的optstring进行解析
1、Linux系统C语言编程连接MySql数据库实现的用户 用户组 用户策略 管理系统(getopt解析命令行参数).c 代码的源文件。 user-usergroup-authoritys.vsd user-usergroup-authoritys.jpg 数据库的图,以及图片。 2、...
下面我通过新建一个test.py的脚本解释下这个模块的的使用 #!/usr/bin/python # -*- coding: utf-8 -*- import sys import getopt if __name__=='__main__': print sys.argv opts, args = getopt.getopt(sys.argv...
要安装此模块,请运行以下命令: perl Build.PL ./Build ./Build test ./Build install SUPPORT AND DOCUMENTATION 安装后,您可以使用 perldoc 命令找到此模块的文档。 perldoc Getopt::Alt 您还可以在以下位置查找...
这是getopt函数的另一个C ++版本,用于解析命令行选项和环境变量。 但是,与其他版本不同,此版本的设计目标是: 易于使用 简单易学 模仿STL的流 键入的最小代码 与STL类型的平滑集成 平台无关(ANSI C ++) 易于...
本篇将介绍python中sys, getopt模块处理命令行参数 如果想对python脚本传参数,python中对应的argc, argv(c语言的命令行参数)是什么呢? 需要模块:sys 参数个数:len(sys.argv) 脚本名: sys.argv[0] 参数1: sys...
例如编译命令:n是选项argc是参数个数(但是不需要去填),argv是所有的参数,这里就是[./test -n 3]三个参数getopt(argc, argv,
2.使用getopt方法 1.使用argv数组 例如:需要执行一个php,并传递三个参数(type=news, is_hot=1, limit=5) 创建test.php <?php print_r($argv); ?> 在命令行执行 php test.php news 1 5 输出: Array ( ...
python解析命令行参数主要有三种方法:sys.argv、argparse解析、getopt解析 方法一:sys.argv —— 命令行执行:python test_命令行传参.py 1,2,3 1000 # test_命令行传参.py import sys def para_input(): print...
第一个工具是一个命令行工具,可将 KiCad .cmp 文件解析为包含组件值和封装 ID 的 .JSON 文件。 第二个工具在浏览器窗口中打开 .JSON 文件并使用数据搜索 ... python kicad_cmp_converter.py test.cmp test.csv csv
perl Build.PL./Build./Build test./Build install或者,如果您没有安装Module :: Build,请键入以下内容: perl Makefile.PLmakemake testmake install依存关系SVN :: Notify具有以下依赖关系: Getopt :: Long此...
tailor.h, getopt.c, getopt.h Tools that are used only by the driver program for I/O purposes. You will not need to know what the code in these files do. Others Required by Visual C++. You do not ...
du, echo, ed, egrep, env, expand, expr, factor, false, fgrep, find, fold, fsync, ftpget, ftpput, getopt, grep, groups, gunzip, gzip, hd, head, hexdump, id, ipcalc, kill, killall, less, link, ...
#include <getopt.h> #include #include #include #include #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) static void pabort(const char *s) { perror(s); abort(); } //static const char *...
Getopt::Long XXX (仅用于调试) ##测试模块 如果您是开发人员,要进行测试,您需要安装App::Prove : $ prove -lv t 另一种选择是使用Build.PL $ ./Build test ##Vim 语法 VIC:trade_mark: 的vim语法在sh
env, expand, expr, false, fgrep, find, fold, ftpget, ftpput, getopt, grep, gunzip, gzip, hd, head, hexdump, kill, killall, ls, lzcat, lzma, lzop, lzopcat, man, md5sum, mkdir, mktemp, mv, od, patch, ...
sudo apt-get install libmoose-perl liburi-perl libmoosex-getopt-perl libsocket6-perl libanyevent-perl sudo cpan AnyEvent::MPRPC::Client Clone from git git clone ...
•Zend_Console_Getopt •Zend_Controller •Zend_Currency •Zend_Date •Zend_Db •Zend_Debug •Zend_Dojo •Zend_Dom •Zend_Exception •Zend_Feed •Zend_File •Zend_Filter •Zend_Form •...
它与getopt_long大致相似,但可用于C ++。 执照 根据分发。 特性 C ++ 03 需要链接 建置状态 (进行中...) 分支 特拉维斯 传送带 codecov.io 滴水 文件 测验 目录 名称 目的 build 链接库的构建脚本 ci ...
q命令行 Qt的命令行解析器(如getopt)。 功能包括选项,开关,参数和自动--version /-帮助生成。 例子 有关示例,请参见examples / test.cpp。