如何在Eclipse CDT应用程序中分配输入文件而不是stdin?

我的应用程序是一个从命令行使用的简单可执行文件,并将stdin作为输入, stdout作为输出,因此它的行为与许多GNU工具一样。 为了测试它,我想设置一个Eclipse CDT DEBUG配置来将文件传递给stdin ,将另一个文件传递给stdout

我在DEBUG Configuration GUI中尝试了一些解决方案,但没有成功:

  1. Common / Standard Input and Output / Input File:我把inputfile.txt放在同一节Output file:Output file: outputfile.txt 。 由于GUI指示工作目录是${workspace_loc:/myprogram} ,它应该没问题,但是当调试器启动时,它会发出警告:

[Invalid file specified for console output: test/WittenACM87ArithmCoding-1.txt.coded] [Invalid file specified for stdin file: test/WittenACM87ArithmCoding-1.txt]

  1. Arguments我放了 outputfile.txt ,这显然不是为此设计的

当然,这两个文件都在工作目录中。 所有尝试都失败了ch = getc(stdin); 带有一些奇怪消息的代码行:

Can't find a source file at "/build/glibc-p3Km7c/glibc-2.24/io/../sysdeps/unix/syscall-template.S" Locate the file or edit the source lookup path to include its location.

这是堆栈:

Thread #1 [myprogram] 31960 [core: 5] (Suspended : Signal : SIGINT:Interrupt)
__read_nocancel() at /build/glibc-p3Km7c/glibc-2.24/io/../sysdeps/unix/syscall-template.S:84 0x7ffff7811700 _IO_new_file_underflow() at /build/glibc-p3Km7c/glibc-2.24/libio/fileops.c:600 0x7ffff77a9a00
__GI__IO_default_uflow() at /build/glibc-p3Km7c/glibc-2.24/libio/genops.c:413 0x7ffff77aab02
_IO_getc() at /build/glibc-p3Km7c/glibc-2.24/libio/getc.c:38 0x7ffff77a54f0 main() at /xxxxxx/src/myprogram.c:20 0x555555554f01

当我直接在控制台中运行应用程序时,它可以工作:

./myprogram outputfile.txt

我假设Eclipse没有设法实现文件重定向到stdinstdout ,所以很明显,我这样做是错误的。 我已经搜索过了,但是这里和这里都没有为我的用例提供解决方案。

因此,为了能够使用Eclipse的调试器,设置Eclipse DEBUG Configuration的正确方法是什么?

实际上,解决方案1使用的是与工作目录无关的相对路径。 使用GUI中的任一按钮Workspace...File System...可以选择已存在的文件。

例如,使用Workspace定义,该字段变为:

${workspace_loc:/myprogram/inputfile.txt} (输出相同)

它有效。 调试器说:

[Console output redirected to file:/.../myprogram/outputfile.txt]