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 我们能 ...
随机推荐
- 【LoadRunner】解决LR11无法录制Chrome浏览器脚本问题
LoadRunner录制脚本时,遇到高版本的IE.FireFox,或者Chrome浏览器,会出现无法录制脚本的问题,下面就来讲一下如何利用LR自带的wplus_init_wsock.exe插件进行脚本 ...
- Tensorflowonspark安装
1.实验环境 Centos7+Python3.6+Java8+Hadoop2.6+Spark2.3+Tensorflow1.10.0 2.Tensorflow安装 最简单的方式:pip install ...
- [转]dwr3框架学习笔记--简介及原理简介
1.DWR简介 DWR(直接web远程访问),DWR是一个Java库,使服务器上的Java和JavaScript的浏览器进行交互和相互调用尽可能简单. DWR 是一个可以允许你去创建 AJAX WEB ...
- ssh问题_2
前一段时间配置hadoop集群环境,发现一个现象,教程中的命令形式是ssh hostname,当然这个hostname应该是在ssh发起者的hosts文件中和相应的IP对应:现在问题来了: 我用的是m ...
- PhalApi 1.4.2 经典封存版 - 码云
https://www.phalapi.net/ PhalApi 1.x 是经典封存版本,已停止更新,历练考验,可放心使用. 主要采用PEAR命名规范,遵循PSR-0,不支持命名空间和composer ...
- password & Encryption
password & Encryption cipher https://dev.tencent.com/login
- 【Python】PYTHON九九乘法表
python2.7 for i in range(1,10): for j in range(1,i+1): print j,'x',i,'=',j*i,'\t', print '\n'pr ...
- mac 倍速播放
Mac的倍速播放,使用工具播放是quick time player,使用方式是,按住 “option” + “>>” 即可调整倍数:
- Visio中ShapeAdded和SelectionAdded
SelectionAdded 和 ShapeAdded 事件的相似之处在于它们都在创建形状之后触发.它们的区别在于,当单个操作添加多个形状时它们的行为方式不同.假定一个 Paste 操作创建三个新建形 ...
- Winpcap网络开发库入门
原文链接地址:http://www.cnblogs.com/phinecos/archive/2008/10/20/1315176.html Winpcap是一个强大的网络开发库,可以实现许多功能:获 ...