如何在Eclipse CDT应用程序中分配输入文件而不是标准输入? [英] How to allocate an input file instead of the stdin in an Eclipse CDT application?

查看:124
本文介绍了如何在Eclipse CDT应用程序中分配输入文件而不是标准输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My application is a simple executable used from the command line and takes stdin as input and stdout as output, so it behaves like many GNU tools. To test it, I want to set up an Eclipse CDT DEBUG Configuration to pass a file to stdin and another one to stdout.

我尝试了一些解决方案,但都在 DEBUG Configuration GUI:

I have tried unsuccessfully a few solutions, all inside the DEBUG Configuration GUI :


  1. 公用/标准输入和输出/输入文件中:我把 inputfile.txt 放在同一部分输出文件:我把 outputfile .txt 。因为GUI指示工作目录为 $ {workspace_loc:/ myprogram} ,所以应该没问题,但是当调试器启动时,它会警告:

  1. In Common / Standard Input and Output / Input File: I put inputfile.txt and in the same section Output file: I put outputfile.txt. As the GUI indicates that the working directory is ${workspace_loc:/myprogram}, it should be alright, but when the debugger is started, it warns :

[为控制台输出指定了无效文件:test / WittenACM87ArithmCoding-1.txt.coded]
[指定了无效文件对于标准输入文件:test / WittenACM87ArithmCoding-1.txt]


  1. 参数我放入< inputfile.txt> outputfile.txt 显然不是为此设计的

  1. In Arguments I put < inputfile.txt > outputfile.txt which is obviously not designed for that

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

Of course, both files are in the working directory. All attempts fails on the ch = getc(stdin); code line with some strange message:

在 /build/glibc-p3Km7c/glibc-2.24/io/../sysdeps/unix/syscall-template.S中找不到源文件
找到该文件或编辑源代码查找包含其位置的路径。

这里是堆栈:

线程#1 [myprogram] 31960 [core:5](挂起:信号:SIGINT:中断)

__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

__GI__IO_default )/build/glibc-p3Km7c/glibc-2.24/libio/genops.c:413 0x7ffff77aab02

_IO_getc()在/build/glibc-p3Km7c/glibc-2.24/libio/getc.c:38 0x7ffff77a54f0
main()位于/xxxxxx/src/myprogram.c:20 0x555555554f01

当我直接在安慰,

。/myprogram< inputfile.txt>我以此为前提,假设Eclipse无法设法实现将文件重定向到 stdin

./myprogram < inputfile.txt > outputfile.txt

c $ c>和 stdout ,所以很明显,我做错了。我已经搜索过,但是此处此处不提供

I assume from this that Eclipse does not manage to realise the files redirections to stdin and stdout, so obviously, I do it the wrong way. I have searched for it, but here and here don't provide solution for my use case.

因此,为了能够使用Eclipse中的调试器,设置Eclipse DEBUG配置吗?

So, in order to be able to use the debugger from Eclipse, what is the right way to set up the Eclipse DEBUG Configuration ?

推荐答案

实际上,解决方案1使用的是与工作目录。使用GUI中的任一按钮 Workspace ... File System ... 可以选择应已

In fact, solution 1 was using a relative path not related to the working directory. Using either button Workspace... or File System... in the GUI enables to select the files which shall already exist.

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

For example with Workspace definition, the field becomes :

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

它有效。调试器说:

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

这篇关于如何在Eclipse CDT应用程序中分配输入文件而不是标准输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆