CMD:程序.exe 1< "A:/input.txt"产生无输出

CMD: program.exe 1< "A:/input.txt" yield no output

本文关键字:txt input 输出 exe lt CMD 程序      更新时间:2023-10-16

我已经更新了这个问题:

int main(int argc, char *argv[]){
cout << "cout argc: " << argc << endl;
cerr << "cerr argc: " << argc << endl;
cout << "cout usatty: " << _isatty(_fileno(stdin)) << endl;
cerr << "cerr usatty: " << _isatty(_fileno(stdin)) << endl;
if (argc == 1 && _isatty(_fileno(stdin)))
{
cout << "cout Error: No space between num and <" << endl;
cerr << "cerr Error: No space between num and <" << endl;
}
}

Cmd 输出:

program.exe 0< "A:/input.txt"
cout argc: 1
cerr argc: 1
cout usatty: 0
cerr usatty: 0
program.exe 1< "A:/input.txt"
cerr argc: 1
cerr usatty: 64
cerr Error: No space between num and <
program.exe 2< "A:/input.txt"
cout argc: 1
cout usatty: 64
cout Error: No space between num and <

现在我可以检测到 <1 和 <2(但不能区分它们(,<0 仍然未被发现。

所以对我来说还有两个问题:

1( 如何打印同时适用于 <1 和 <2 的错误消息

2( 如何检测 <0

C++程序打开了三个标准文件:编号0处的标准输入、编号1处的标准输出和编号2处的标准错误(C++也有带std::clog的标准日志,但它与标准输出相同,只是它没有缓冲(。

你对1<所做的是尝试将输入重定向到标准输出。这当然是行不通的。

当你在1<之间有一个空格时,就像在1 <中一样,然后你把1作为参数传递给程序(程序将被放置在argv[1]中,索引与参数无关(,重定向到标准输入。