gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 04:17:42 25 4
gpt4 key购买 nike

我的应用程序是一个从命令行使用的简单可执行文件,需要 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com