Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Eclipse Input Output Redirection with < and >
Eclipse Input Output Redirection with < and > [message #1781568] Thu, 08 February 2018 18:44 Go to next message
Brian Chu is currently offline Brian ChuFriend
Messages: 3
Registered: February 2018
Junior Member
So in the terminal, I can run my program with
./letter --stack -b ship -e shot -c --output W < input.txt > output.txt


How do I achieve the same functionality in Eclipse? I've figured out how to do --stack -b ship -e shot -c --output W by going to the arguments tab under Run configuration.

I've looked online and seen a lot of posts about using the Common tab to input and output redirection but I can't get it working. When I check only the input file, it doesn't work and the Debug perspective shows it's stuck somewhere trying to read from a stream. When I check allocate console and input file, then it gets stuck on user input (aka I can manually type stuff) in the console.

So how do I get < input.txt and by extension > output.txt working?
Re: Eclipse Input Output Redirection with < and > [message #1781590 is a reply to message #1781568] Fri, 09 February 2018 04:20 Go to previous messageGo to next message
David VavraFriend
Messages: 786
Registered: October 2012
Senior Member
Eclipse launches the command as a new process without using a shell.
You probably should execute a shell command that then executes your program
Under Linux, the following run configuration (note the command and arguments are in separate tabs):
/usr/bin/bash -c "pwd; echo 'pstree -a -s $$' > tmp;  bash -p < tmp"

produces
/home/dvavra/proj/HCP-FANN
systemd --switched-root --system --deserialize 23
  └─lightdm
      └─lightdm --session-child 12 19
          └─sh /etc/xdg/xfce4/xinitrc -- vt
              └─xfce4-session
                  └─xfce4-panel --display :0.0 --sm-client-id 26f5d9e4b-868b-48f5-a436-a94ab1f73c5b
                      └─eclipse
                          └─java -Dosgi.requiredJavaVersion=1.8 -Dosgi.instance.area.default=@user.home/eclipse-workspace ...
                              └─bash -c pwd; echo 'pstree -a -s $$' > tmp;  bash -p < tmp
                                  └─bash -p
                                      └─pstree -a -s 28855

Note that the first bash command (shown after java) is executed directly.
This double use of bash is only for illustration.
Executing bash -c 'pstree -s $$' causes the invocation of bash to vanish.
systemd --switched-root --system --deserialize 23
  └─lightdm
      └─lightdm --session-child 12 19
          └─sh /etc/xdg/xfce4/xinitrc -- vt
              └─xfce4-session
                  └─xfce4-panel --display :0.0 --sm-client-id 26f5d9e4b-868b-48f5-a436-a94ab1f73c5b
                      └─eclipse
                          └─java -Dosgi.requiredJavaVersion=1.8 -Dosgi.instance.area.default=@user.home/eclipse-workspace ...
                              └─pstree -a -s 29210


Under Windows you should execute cmd.exe /c "your command"

[Updated on: Fri, 09 February 2018 04:23]

Report message to a moderator

Re: Eclipse Input Output Redirection with < and > [message #1783513 is a reply to message #1781590] Tue, 13 March 2018 18:38 Go to previous messageGo to next message
Brian Chu is currently offline Brian ChuFriend
Messages: 3
Registered: February 2018
Junior Member
How do I do this within eclipse? Do I have to be doing this in terminal? Starting a new project and very confused. If it's too complicated, just let me know and I'll switch to Visual Studio. Is it even possible to do this within eclipse? Every IDE I've seen allows for io redirection, but I can't find any documentation or anything within eclipse that supports this. Also I'm very unfamiliar with shell...

[Updated on: Tue, 13 March 2018 18:43]

Report message to a moderator

Re: Eclipse Input Output Redirection with < and > [message #1783547 is a reply to message #1783513] Wed, 14 March 2018 03:33 Go to previous message
David VavraFriend
Messages: 786
Registered: October 2012
Senior Member
Sorry, executing a single shell command seems easier to me.
It also allows execution of multiple commands in a launch.

Eclipse wants to insert itself as the input and output streams
but you can also override the input and output streams in the Common tab of a launch configuration dialog
http://help.eclipse.org/oxygen/index.jsp?topic=%2Forg.eclipse.cdt.doc.user%2Ftasks%2Fcdt_o_run_config.htm

There doesn't seem to be any documentation for it though it seems to be available since at least Kepler.

Previous Topic:Unexpected flash start address
Next Topic:Unable to create variable object
Goto Forum:
  


Current Time: Tue Oct 23 17:11:05 GMT 2018

Powered by FUDForum. Page generated in 0.02849 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top