1

I was writing a simple console application in Objective C.

I have tried system("clear") but I am getting this message on console

"TERM environment variable not set."

Can anyone explain me what this is all about ?

I am very new to both OSX and Objective C. and I am sorry if this question is too dumb as I have not programmed much on *nix. (I have been doing a lot of Java and PHP development in my college days).

Amogh Talpallikar
  • 12,084
  • 13
  • 79
  • 135
  • possible duplicate of [Clearing output of a terminal program Linux C/C++](http://stackoverflow.com/questions/1348563/clearing-output-of-a-terminal-program-linux-c-c) – Caleb Dec 12 '11 at 05:16
  • The answer will be found in the C standard library -- there's nothing here that's specific to Objective-C or MacOS X. Or perhaps I should say: there's nothing in Objective-C or the Cocoa framework that will help -- you'll need to look to C and Unix for the answer. – Caleb Dec 12 '11 at 05:18
  • Thanks but on a lot of C/Unix forums I saw, I got system("clear");, as the answer but I am getting this error. meaning of the error is my actual question. wait lemme edit the question before people vote it down. – Amogh Talpallikar Dec 12 '11 at 05:32

1 Answers1

6

The TERM environment variable tells your program what type of terminal its running on. Each type of terminal displays data and responds to commands in its own way. For example, a VT100 terminal works quite differently from a IBM 3270 terminal.

The error message you're seeing says that the TERM environment variable isn't set, probably because you're trying to launch your program from within Xcode. You can add environment variables to be set in Xcode 4's scheme settings. As rob mayoff points out below, though, Xcode's console isn't a proper terminal emulator, so trying to run your program within Xcode isn't going to give you the results you're looking for.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • 2
    But Xcode's console isn't a real terminal emulator. It doesn't handle escape sequences, so setting TERM won't let him clear the console. – rob mayoff Dec 12 '11 at 05:41
  • 1
    @robmayoff Good point -- updated my answer to include that fact. – Caleb Dec 12 '11 at 05:59
  • 1
    Thanks Rob and Caleb. I would have voted up your answer. but I don't have those "reputation" points. :P :) – Amogh Talpallikar Dec 12 '11 at 06:21
  • 1
    But why does a program need a terminal emulator? What sort of functions are provided by this terminal? – Martin Konecny May 25 '12 at 15:44
  • 1
    @MartinKonecny [Different terminals](http://en.wikipedia.org/wiki/Computer_terminal) have different capabilities. For example, some can only display lines of characters; others can display in reverse field (background and foreground colors switched), bold, colors, and so on. Some have fixed screen dimensions, others can change on the fly. Some can do graphics, others only text. The terminal is the (terminal-based) program's connection to the user; a program needs to know what kind of terminal it's talking to if it wants to take advantage of that terminal's capabilities. – Caleb May 25 '12 at 16:09