Thomas Kejser
Thomas Kejser

Reputation: 1294

How do redirect STDOUT out of XCode compiled Command Line executable?

I have a C++ program that writes to stdout that I am trying to compile into a command line utility in XCode. I need the program compiled into a release build (which it seems, XCode calls an Archive - go figure), not run it as debug.

I basically want to pipe the output of my program into a textfile like this

MyProgram > TextFile.txt

I can compile the program into a command line and run it like this via a Bash shell like this:

Open MyProgram

This spawns a new process (not what I want). However, I could live with that if this worked:

Open MyProgram > TextFile.txt

...But it doesnt :-(. If I try to just run MyProgram directly from Bash, I get the error: -bash: MyProgram: command not found.

What am I doing wrong? How can I compile my command line tool to NOT require the Open command under Mac OSX?

Thanks for any help you can provide. I am picking up C++ on the Mac platform and I am beginning to find it quite it a bit more troublesome than Visual Studio. Does it ever get less painful to work with? :-)

Upvotes: 1

Views: 1448

Answers (1)

gcochard
gcochard

Reputation: 11734

  • Make your project a Command Line Tool. This will make it so you can run it from the command line directly.

  • Run it by typing ./MyProgram or ./MyProgram > TextFile.txt not open MyProgram.

Upvotes: 4

Related Questions