开发者

error: Command not found, on sending command line arguments

开发者 https://www.devze.com 2023-03-04 20:22 出处:网络
I have a very simple program below. #include<stdio.h> void main(int argc, char *argv[]) { printf(\"\\n %s\",argv[3]);

I have a very simple program below.

#include<stdio.h>
void main(int argc, char *argv[])
{
  printf("\n %s",argv[3]);
}

Say the executable is named a.out and ru开发者_JAVA技巧nning it as $./a.out open path/to/my/file O_WRONLY|O_APPEND gives Command no found error. where as running it as running it as $./a.out open path/to/my/file O_WRONLY gives output O_WRONLY.

Is it because of |

Thanks for you valuable time.


Your shell takes the | before O_APPEND as a pipe, and doesn't recognize this command (because it doesn't exist) try $./a.out open path/to/my/file "O_WRONLY|O_APPEND".

Also, don't use void main, use int main (some people here might get a heart attack if they see it :) )


The pipe character | has a special meaning to the shell: it creates a pipeline, where the output of one process is piped into the input of another process. When you type foo | bar, the shell spawns the two processes with command lines of foo and bar and connects the output of the former to the input of the latter.

To avoid this behavior, put quotes around your command line arguments:

$ ./a.out open path/to/my/file "O_WRONLY|O_APPEND"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号