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

标签 c debugging configuration eclipse-cdt stdin

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

我试过几个解决方案都没有成功,都在DEBUG Configuration里面界面:

  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.

这是堆栈:

Thread #1 [myprogram] 31960 [core: 5] (Suspended : Signal : SIGINT:Interrupt)<br/> __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<br/> __GI__IO_default_uflow() at /build/glibc-p3Km7c/glibc-2.24/libio/genops.c:413 0x7ffff77aab02<br/> _IO_getc() at /build/glibc-p3Km7c/glibc-2.24/libio/getc.c:38 0x7ffff77a54f0 main() at /xxxxxx/src/myprogram.c:20 0x555555554f01

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

./myprogram < inputfile.txt > outputfile.txt

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

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

最佳答案

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

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

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

而且它有效。调试器说:

[控制台输出重定向到文件:/.../myprogram/outputfile.txt]

关于c - 如何在 Eclipse CDT 应用程序中分配输入文件而不是标准输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50061178/

相关文章:

c - 使用 OpenFlow 构建/链接 ns3 网络模拟器时出错

debugging - 在 ntdll 中使用 gdb 进行调试时突然出现断点

eclipse - 标签以选择 eclipse 中的自动完成项目?

c - 指针和取消引用

c - 如何用字符串替换宏?

c - 当没有空格时区分scanf中的字符串和int

javascript - 如何将CasperJS调试结果打印到文本文件

javascript - 如何在用户单击框中删除文本?

nhibernate - Fluent NHibernate Automapping 与抽象基类

grails - Grails-外部化配置重新启动