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

五迷三道 提交于 2019-12-20 05:36:06

问题


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? :-)


回答1:


  • 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.



来源:https://stackoverflow.com/questions/11021452/how-do-redirect-stdout-out-of-xcode-compiled-command-line-executable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!