开发者

What's Python's os.system() equivalent to cocoa/Objective-C?

开发者 https://www.devze.com 2023-02-16 14:43 出处:网络
I\'d like to run some terminal command within my Mac program. For example, I normally use mate abc.txt or python abc.py from my shell to open Text Mate or running python script.

I'd like to run some terminal command within my Mac program. For example, I normally use mate abc.txt or python abc.py from my shell to open Text Mate or running python script.

How can I do the same thing with Cocoa/Objective-C?

I thought about this method, but I prefer just running in one line.

For example, when users enter "python abc.py", I just run the command as if it's in the Terminal.app. Python's equivalent command is os.system().

What's Python's os.system() equivalent to cocoa/Objective-C?

<-- inputItem TextField

NSString* item = [inputItem stringValue];
[NSRuncommandLikeShell item]; <-- ????

The enviro开发者_Python百科nment variables should be retained so that I don't need to run '/usr/bin/python'.

EDIT

I can use ~/.MacOSX/environment.plist file for setup path environment. Or, I also could use this utility for GUI.


You can use an NSTask object. If you don't like all of the setup that goes in to this, you can create an NSTask category that does it for you.


You can use the C runtime system() call.

#include <stdlib.h>

system([item UTF8String]);
0

精彩评论

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