Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I clear the console in Objective-C

I'm making a console-based application in Objective-C which relies on being able to clear the console periodically. How can this be done? All I've seen on SO and Google were ways to have the developer clear the console with X-Code, but that will not do.

One solution I found on Yahoo! Answers told me to do the following, but it does not run due to being unable to find a file:

NSTask *task;
task = [[NSTask alloc]init];
[task setLaunchPath: @"/bin/bash"];

NSArray *arguments;
arguments = [NSArray arrayWithObjects: @"clear", nil];
[task setArguments: arguments];

[task launch];
[task waitUntilExit];
like image 798
Ky. Avatar asked Apr 10 '12 03:04

Ky.


1 Answers

Try using :

system( "clear" );

Important headers :

#include <stdlib.h>

Hint : Objective-C is still C, right?


UPDATE :


In case of a "TERM environment variable not set." error :

1) Run the program, directly from your terminal (or just ignore the error while testing it in Xcode; it's supposed to run in a normal terminal anyway, huh?)

2) Set the TERM variable in your Scheme's settings. To what? Just run this in your terminal to see what "TERM" should be :

DrKameleons-MacBook-Pro:Documents drkameleon$ echo $TERM
xterm-256color

enter image description here

like image 134
Dr.Kameleon Avatar answered Sep 18 '22 11:09

Dr.Kameleon