Lipika Deka
Lipika Deka

Reputation: 3884

error: Command not found, on sending command line arguments

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 running 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.

Upvotes: 0

Views: 1020

Answers (2)

Adam Rosenfield
Adam Rosenfield

Reputation: 400492

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"

Upvotes: 2

MByD
MByD

Reputation: 137382

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 :) )

Upvotes: 2

Related Questions