2
我正在編寫一個程序代理,它將stdout等重定向到文件中,其用法如下:proxy [-i infile] [-o outfile] [-e errfile] cmd [options] 。C強制getopt先停止參數
所以我想強制getopt在到達cmd時停止,因爲它不應該解析選項。
我讀了關於環境變量POSIXLY_CORRECT,但我想要使它獨立於此。
所以我的問題是如何達到這一點。
我的代碼的一部分,到目前爲止
while ((opt = getopt (argc, argv, "i:o:e:")) != -1)
switch (opt)
{
case 'i':
i = 1;
strcpy(input, optarg);
break;
case 'o':
o = 1;
strcpy(output, optarg);
break;
case 'e':
e = 1;
strcpy(error, optarg);
break;
default:
fprintf(stderr, "usage: proxy [-i infile] [-o outfile] [-e errfile] <cmd> [options]\n");
return -1;
}
這將進入默認情況下,當對CMD的選項給出:(所有的時間
很好,這個小「+」解決了我所有的問題:) 非常感謝! – sch0rschi 2014-11-23 14:32:25