Objective-C command-line tool encoding that accepts inputs, clears the screen, and then displays

Hope I don't ask too much here.

I would like to create a command line tool that will run in a terminal window. It will receive data from the terminal, do something with the line, clear the screen, and then output the lines.

#import <Foundation/Foundation.h> #include <stdlib.h> int main (int argc, const char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSLog (@"Running...."); // take the argument as an NSString // do something with the NSString. // clear the terminal screen. // output the manipulated screen. [pool drain]; return 0; } 

Is it possible? Any tips? I would like to code this as much as possible in Objective-C.

Thanks,

EDIT 1 *

To be clear, I would like to constantly input and output from the program. In other words, you will need to enter data after running the executable file. Not only when it is initially executed.

+4
source share
1 answer

It is possible. Use the Command Line Tool template in Xcode when creating a project.

A quick example might be:

 #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { @autoreleasepool { char input[50]; while (true) { // take the argument as an NSString NSLog(@"Enter some text please: "); fgets(input, sizeof input, stdin); NSString *argument = [[NSString stringWithCString:input encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; // do something with the NSString. NSString *uppercase = [argument uppercaseString]; // clear the terminal screen. system("clear"); // output the manipulated screen. NSLog(@"Hello, %@!", uppercase); } } return 0; } 
+4
source

Source: https://habr.com/ru/post/1391458/


All Articles