【发布时间】:2012-05-30 16:12:54
【问题描述】:
我正在尝试运行一个简单的任务,该任务必须执行回显“Hello World”
这是我的代码:
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath:@"/bin/bash"];
NSArray *arguments;
arguments = [NSArray arrayWithObjects:@"echo","hello world" nil];
[task setArguments: arguments];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
[task setStandardError: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
//...
//Code to get task response
一直给我没有这样的文件或目录错误..我做错了什么?
【问题讨论】:
-
你为什么要让 shell 这样做? NSTask 的优点之一是不必通过 shell。你可以直接运行 echo 命令(单机版,不是 bash 的)。
-
@Peter Hosey Care 发布如何通过 NSTask 独立运行 echo 命令?
标签: objective-c cocoa command nstask