错误:发送命令行参数时未找到命令
我下面有一个非常简单的程序。
#include<stdio.h>
void main(int argc, char *argv[])
{
printf("\n %s",argv[3]);
}
假设可执行文件名为 a.out 并将其运行为 $./a.out open path/to/my/file O_WRONLY|O_APPEND 给出命令未发现错误。 运行它就像运行它一样 $./a.out open path/to/my/file O_WRONLY 给出输出 O_WRONLY.
是不是因为|
感谢您宝贵的时间。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 shell 将
O_APPEND
之前的|
作为管道,并且无法识别此命令(因为它不存在)尝试$./a.out打开路径/到/我的/文件“O_WRONLY|O_APPEND”
。另外,不要使用
void main
,使用int main
(这里有些人如果看到它可能会心脏病发作:))Your shell takes the
|
beforeO_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
, useint main
(some people here might get a heart attack if they see it :) )管道字符
|
对 shell 具有特殊含义:它创建一个管道,其中一个进程的输出通过管道传输到另一个进程的输入。当您输入foo | bar
时,shell 使用foo
和bar
命令行生成两个进程,并将前者的输出连接到后者的输入。为了避免这种行为,请在命令行参数两边加上引号:
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 typefoo | bar
, the shell spawns the two processes with command lines offoo
andbar
and connects the output of the former to the input of the latter.To avoid this behavior, put quotes around your command line arguments: