22

I have a C++ application, to which i need to send an End of Transmission signal.

I can do a Ctrl+D on the console, but when I try that within Eclipse, it doesn't work.

I am using Eclipse Galileo with CDT.

gsamaras
  • 71,951
  • 46
  • 188
  • 305
anon
  • 1,071
  • 2
  • 8
  • 19

3 Answers3

21

It seems to be a not yet resolved bug: bug 159803 (resolved in September 2015, for CDT 9.0)

Since Eclipse 3.1 it is possible to signal EOF (using CTRL + D/Z - bindable in key preferences) in console view, and I tested this successfully with Eclipse 3.2.1 using a simple Java app.
CDT on the other hand will not recognize EOF when in console view.
There is one exception though.

If I run a C/C++ Local App and uncheck "Connect process input & output to a terminal" in the main configuration tab, the console view will recognize EOF.

However, this change does not affect the console view when in the Debug perspective. So while debugging it is still impossible for me to send an EOF signal to the running application.

Even though it is considered "resolved", this comment shows the issue persists.


Update 4 years later (Dec 2014), Fernando Gonzalez-Sanchez mentions in the comments:

Workaround checkbox no longer available in UI.
Problem still happening in OpenSUSE 12 & Eclipse CDT Luna 4.4.1.


Update March 2015:

Muhammad Annaqeeb mentions in the comments:

There is a new workaround mentioned in the bug page:

In Kepler 4.3 eclipse.buildId=4.3.0.M20130911-1000 on Linux the problem still exists in the Java console. I found the following workaround:

"If you leave the console to focus on another view, and then refocus on the console, then Ctrl-D (EOF) works as expected."

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
8

I just found a solution to this problem:

When you finish entering your inputs on console, click on another window (editor, Project Explorer, etc.), then click back on console. Hitting Ctrl + Z will work now.

Matt
  • 796
  • 12
  • 25
  • Wonderful. I had the same problem with Eclipse version 2021-12 (4.22.0), and doing this solves it easily. Another thing that might be worth mentioning is that this problem occurs only after the program has been run for the first time, and not recompiled. – GPWR Nov 19 '22 at 23:40
  • I'm glad my solution helped, although It's disappointing to see this problem still exists after so many years. – Matt Nov 21 '22 at 01:50
0

One way you might consider sending ctrl+d to the console is by doing a little BASH injection in your program arguments. appending something like "& sleep 10 && echo -e '\x04\c' > /dev/stdin" for example will wait 10 seconds before sending the ctrl-D command. though you could easily modify it for some other non-timebased condition as well. In addition, you could open /dev/stdin from your C++ program as a file, then write the value 0x04 into it then flush to achieve the same effect from your program.

  • Actually I just realized you may want to write to "/dev/console" instead of stdin –  Jan 17 '11 at 15:33