Saturday, February 11, 2012

IO Redirection and pipes in Eclipse (and xCode)

I have a program that produces two executable files.  One is called "render" and the other is called "runsim".

The way that i would run the program is to open up a console/terminal and enter:
"./runsim < env0 | ./render"

render handles the graphics and runsim controls the movement of the objects. "env0" is a textile that holds that parameters of what the graphic is.


If you want this to run in eclipse there are two things that you must do
1) use your custom makefile
2) add command line arguments to the make file

*it is assumed that you are using linux

To use your own make file you must go to:
properties-->C/C++ Build --> Makefile generation
Then
you must untick "Generate Makefile automatically"

(You might have to set the build location)

Now if you want to be able to use command line arguments such as pipes and IO redirects it is helpful to simply add new stuff to the make file

Simply add
<name> : <command line arguments> 
===============================
For example lets say this is my make file
===============================
all: render runsim
render: render.o
     render.cpp thing.cpp thing2.cpp -o render

runsim: runsim.o
     runsim.cpp it.cpp. it2.cpp -o runsim
----------------------------------------------------------

I would add "special: ./runsim < env0 | ./render"

==============================
the resulting makefile
==============================

all: render runsim special

special:
     ./runsim < env0 | ./render

render: render.o
     render.cpp thing.cpp thing2.cpp -o render

runsim: runsim.o
     runsim.cpp it.cpp. it2.cpp -o runsim
----------------------------------------------------------

When you build using this makefile, eclipse will actually run the command line specified by special.
Now if only I could get it to work on osx.  If you run the above example on osx it will actually complain about "<" saying that there is no rule to make target.  I tried getting it to run on Xcode 4 but it doesn't like it.  it won't even work on the console.  There must be a special character that OSX like to use.  If anyone knows how this is done, please share**

**UPDATE this can work in Xcode 4
(The problem i had was that Xcode was inserting spaces instead of tabs
in my makefile.  makefiles require that you use tabs not spaces (marked <tabs>)

==============================
special = ./runsim < env0 | ./render
all: render runsim 
<tabs>$(special)
render: render.o
<tabs>render.cpp thing.cpp thing2.cpp -o render

runsim: runsim.o
<tabs>runsim.cpp it.cpp. it2.cpp -o runsim
----------------------------------------------------------
Alternatively, if you don't want the command line arguments to run when you "make all"
you can modify it such that you would have to type "make special"

==============================
CMD= ./runsim < env0 | ./render
all: render runsim 

special:
<tabs> $(CMD)

render: render.o
<tabs>render.cpp thing.cpp thing2.cpp -o render

runsim: runsim.o
<tabs>runsim.cpp it.cpp. it2.cpp -o runsim
----------------------------------------------------------

i'm not sure how to make Xcode invoke make special.  right now all it does is the default
meaning that it will run make all since "all" was the first one it saw.  If somehow I could
have it run make all and then after that make special.  I do not know the answer to that.  If anyone out
there knows, Please share.








No comments:

Post a Comment