给出5个参数,但终端中只有3个 [英] Giving 5 Arguments but getting just 3 in terminal
问题描述
我想将文件传递到c程序中.
I want to pass a file into a c program.
如果我在IDE中执行此参数
If I am doing it in the IDE this arguments
./test string string < test.txt
返回argc = 5
,但是在终端上我只是得到argc = 3
.
return argc = 5
, but on the terminal I am just getting argc = 3
.
似乎是因为<" -符号,我想使用它来表示我正在传递文件.
It seems, that its because of the "<" - symbol, I wanted to use this, to indicate that I am passing a file.
< 是什么意思?我在Tilix终端上使用Ubuntu
What does < mean? I am using Ubuntu with Tilix terminal
推荐答案
重定向是由Shell执行的,对您的程序不(直接)可见.
Redirection is performed by the shell, and is not (directly) visible to your program.
./test string string < test.txt
表示
- 打开
test.txt
以读取文件描述符1 - 使用参数
string
和string
运行
./test
- Open
test.txt
for reading on file descriptor 1 - Run
./test
with the argumentsstring
andstring
在第2点运行的程序将继承父对象的文件描述符,因此其标准输入将连接到打开的文件句柄(而不是Shell的当前标准输入,它可能是您的终端,也可能是其他文件句柄).
The program run in point 2 will inherit the parent's file descriptors, so its standard input will be connected to the opened file handle (rather than the shell's current standard input, which could be your terminal, or a different file handle).
顺便说一句,您可能希望避免调用程序test
,尽管只要您不忘记使用显式路径来调用它,这是无害的.
As an aside, you probably want to avoid calling your programs test
, though as long as you don't forget to invoke it with an explicit path, this is harmless.
这篇关于给出5个参数,但终端中只有3个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!