Execute a terminal command from a Cocoa app
http://stackoverflow.com/questions/412562/execute-a-terminal-command-from-a-cocoa-app
in the spirit of sharing... this is a method I use frequently to run shell scripts. you can add a script to your product bundle (in the copy phase of the build) and then have the script be read and run at runtime. note: this code looks for the script in the privateFrameworks sub-path. warning: this could be a security risk for deployed products, but for our in-house development it is an easy way to customize simple things (like which host to rsync to...) without re-compiling the application, but just editing the shell script in the bundle.
//------------------------------------------------------
-(void) runScript:(NSString*)scriptName
{
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath: @"/bin/sh"];
NSArray *arguments;
NSString* newpath = [NSString stringWithFormat:@"%@/%@",[[NSBundle mainBundle] privateFrameworksPath], scriptName];
NSLog(@"shell script path: %@",newpath);
arguments = [NSArray arrayWithObjects:newpath, nil];
[task setArguments: arguments];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
NSData *data;
data = [file readDataToEndOfFile];
NSString *string;
string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog (@"script returned:\n%@", string);
}
//------------------------------------------------------
Execute a terminal command from a Cocoa app的更多相关文章
- JFace dailog button事件中刷新透视图异常 Trying to execute the disabled command org.eclipse.ui.window.closePerspective
报错的代码为 protected void buttonPressed(int buttonId) { Display.getDefault().syncExec(new Runnable() { p ...
- 错误解决:SharePoint Designer 2010编辑后,出现数据源控件未能执行插入命令,data source control failed to execute the insert command
打了SharePoint 2010 最新的SP 2的补丁,但是使用SharePoint Designer 2010 定义任何一个列表的“插入视图”时,总是出现标题那样的错误: 数据源控件未能执行插入命 ...
- svn Please execute the 'Cleanup' command. 问题解决
1由于使用svn 更新文件出错,导致svn中断,然后就一直循环出现 ‘’Please execute the 'Cleanup' command‘’ 问题: 查找网上方案 . 有使用sqlite3 ...
- Build step 'Execute Windows batch command' marked build as failure
坑爹的Jenkis,在执行windows命令编译.NET项目的时候命令执行成功了,但是却还是报了这样一个错: Build step 'Execute Windows batch command' ma ...
- 解决SVN Cleanup时遇到错误信息:Cleanup failed to process the following paths:xxxxxxx Previous operation has not finished: run 'cleanup' if it was interrupted Please execute the 'Cleanup' command.
解决SVN Cleanup时遇到错误信息:Cleanup failed to process the following paths:xxxxxxx Previous operation has no ...
- SVN更新报错问题(Please execute the 'Cleanup' command)
SVN更新报错问题(Please execute the 'Cleanup' command) https://segmentfault.com/a/1190000012571289 svn: E20 ...
- 【SVN】Please execute the 'Cleanup' command.
背景 项目有个新的bug,我需要提取一个新的分支,但是提取之后,更新分支出现了这个问题 Please execute the 'Cleanup' command. 原因 由于使用SVN更新文件出错,导 ...
- SVN报错之“Error: Please execute the 'Cleanup' command. ”
问题 Error: Please execute the 'Cleanup' command. 需要清理下,注意SVN拉数据的时候别打开其中的问题 解决方案
- 如何从Terminal Command Line编译并运行Scope
Ubuntu SDK我们大部分的开发者是非常有效的.它甚至可以帮助我们进行在线调试.在这篇文章中,我们介绍了如何使用command line编译和执行我们scope. 1)创建一个主Scope 我们能 ...
随机推荐
- Qt 解析网络数据出现ssl错误
最近写了点小东西,哈哈, 网络部分是同学帮我搞的 在编译的时候,出现了一下错误 qt.network.ssl: QSslSocket: cannot call unresolved function ...
- cmd命令笔记
查看端口信息:netstat -ano eg. netstat -ano|findstr 0.0.0.0:443 根据pid查看进程信息等:wmic process get name,executab ...
- JSONP跨域jQuery处理整理(附天气数据实例)
写在前面 跨域的解决方案有多种,其中最常见的是使用同一服务器下的代理来获取远端数据,再通过ajax进行读取,而在这期间经过了两次请求过程,使得获取数据的效率大大降低,这篇文章蓝飞就为大家介绍一下解决跨 ...
- C++STL——vector
一.相关定义 vector 数组 随机访问迭代器 快速随机访问元素 尾部进行快速随机地插入和删除操作 特征: 能够存放任意类型: 访问vector中的任意元素或从末尾添加元素都可以在常量级时间复杂度内 ...
- libevent显式调用事件处理
) { SearchAcceptListen2(p_ev_arg->listen_fd,,¬ify_event,base); event_base_loop(base, EVLOO ...
- 基于phonegap,html5,ratchet,handlebars等技术的微表情APP
该app是由很多有意思的微表情构成的,支持40种表情,并且每种表情都有不同的状态,主要有搜索表情,分享表情,摇一摇换表情等功能.目前只支持安卓版.由前期构思,到技术选型,到界面设计,到编码测试,再到发 ...
- mysql原理以及相关优化
说起MySQL的查询优化,相信大家积累一堆技巧:不能使用SELECT *.不使用NULL字段.合理创建索引.为字段选择合适的数据类型..... 你是否真的理解这些优化技巧?是否理解其背后的工作原理?在 ...
- 【转】 cocos2dx 3.x C++搭建protobuf环境
http://blog.csdn.net/ganpengjin1/article/details/50964961 Cocos2dx 里面在网络游戏通信这一块一般我们都会采用protobuf来进行通信 ...
- PAT 1020 月饼
https://pintia.cn/problem-sets/994805260223102976/problems/994805301562163200 月饼是中国人在中秋佳节时吃的一种传统食品,不 ...
- 更新协同开发工具SVN的链接的服务器地址
公司内的协同开发工具使用的SVN,因为换了个服务器需要重置SVN地址,一下子有点措手不及. 研究了下SVN的操作菜单,发现有一个功能“重新定位”,应该就是我要找的了,试了一下果真没错,记录下 第一步: ...