开发者

how to get command line arguments within running terminal app

In MAC OS i've created a terminal app through objective C which gets command line argument on the launch through the main function.

Now I need to get additional in开发者_如何学JAVAputs at the runtime. So how to get them at runtime? Does the

[[NSRunLoop mainRunLoop] run]

help achieving this purpose?


As Félix Saparelli noted, you're not talking about getting "command-line arguments" in the sense of the arguments passed to your program on the command line, e.g. the thisfile in a command such as cat thisfile, you're talking about having your program accept commands or, at least, accepting input from the terminal, so, as he said, you need to read from the standard input.

NSRunLoop won't, by itself, do that for you. You could just treat your program as a regular UN*X program that just happens to be written in Objective-C, either using standard C library routines such as, for example, fgets(), or Foundation classes such as NSString, assuming NSString's stringWithContentsOfFile method doesn't do something non-useful such as trying to read in the entire file and using it as a string, because "read the entire file" is not generally useful when reading the standard input (it will not read a line at a time, it'll just keep reading until you type control-D).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜