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

How to allocate an input file instead of the stdin in an Eclipse CDT application?

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

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

  1. Common / Standard Input and Output / Input File:中我输入了inputfile.txt,在同一部分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 中我放了 < inputfile.txt > 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.

这是堆栈:

线程#1 [myprogram] 31960 [核心:5](暂停:信号:SIGINT:Interrupt)<br> __read_nocancel() 在 /build/glibc-p3Km7c/glibc-2.24/io/../sysdeps/unix/syscall-template.S:84 0x7ffff7811700 _IO_new_file_underflow() 在 /build/glibc-p3Km7c/glibc-2.24/libio/fileops.c:600 0x7ffff77a9a00<br> __GI__IO_default_uflow() 在 /build/glibc-p3Km7c/glibc-2.24/libio/genops.c:413 0x7ffff77aab02<br> _IO_getc() 在 /build/glibc-p3Km7c/glibc-2.24/libio/getc.c:38 0x7ffff77a54f0 main() 在 /xxxxxx/src/myprogram.c:20 0x555555554f01

当我直接在控制台中 运行 应用程序时,它有效:

./myprogram < inputfile.txt > outputfile.txt

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

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

事实上,解决方案 1 使用的是与工作目录无关的相对路径。在 GUI 中使用按钮 Workspace...File System... 可以 select 应该已经存在的文件。

例如,对于工作区定义,字段变为:

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

并且有效。调试器说:

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