Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 获取关系运算符或按位右移作为命令行参数_C - Fatal编程技术网

C 获取关系运算符或按位右移作为命令行参数

C 获取关系运算符或按位右移作为命令行参数,c,C,您好,我正在尝试获取main的命令行参数,我的参数类似于a.dat>b.dat或a.dat b.dat>>c.dat,但我无法获取或> int main(int argc, char** argv) { int i; for(i=0; i<argc; i++) { if (!strcmp(">", argv[i])) { printf("here is comes\n"); }

您好,我正在尝试获取main的命令行参数,我的参数类似于a.dat>b.dat或a.dat b.dat>>c.dat,但我无法获取
>

int main(int argc, char** argv)
{

    int i;
    for(i=0; i<argc; i++)
    {
        if (!strcmp(">", argv[i]))
        {
           printf("here is comes\n");
        }
        else    
        {
            printf("%s\n",argv[i]);
        }
    }
    return 0;
}
int main(int argc,char**argv)
{
int i;

for(i=0;i
>
在shell中具有特殊意义。如果要将它们作为参数传递,则需要对它们进行转义。例如:
a.dat\>b.dat
a.dat b.dat\>\>c.dat

在大多数(所有?)shell中,
表示将命令的输出重定向(截断并写入)到文件,
>
表示追加(现有内容已保存)。 例如:

$ ls > out #overwrite or create a file called 'out' with the output of 'ls' command.

$ ls >> out2 #append or create a file called 'out2' with the output of 'ls' command.

在Windows中,可以将参数括在引号中,例如

conf a.dat ">" b.dat

系统会删除引号。

我需要从Windows运行程序conf
file1.dat file2.dat>file3.dat
,它们直接输出到一个文件中。我认为值得一提的是它们的用途。
a.dat>b.dat
获取a.dat的所有内容并将其写入b.dat
a.dat>>b.dat
获取a.dat的所有内容,然后将其附加到b。dat@hkn正确。但仅当
a.dat
是一个可执行文件时。类似地,
>
附加了一些信息。我已经用一些信息更新了答案。我的答案下OP的注释是Windows,但像您这样的一些语法会给出消息“命令的语法不正确”,以及其他语法(如您的第一个示例),仍然将输出重定向到文件。@WeatherVane哪个命令会因该消息而失败?这只是一个示例,我不知道OP正在使用windows。此外,答案(即转义)也应该适用于windows。