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 我们能 ...
随机推荐
- MySQL 5.6查看数据库的大小
1. use information_schema; 2. select concat(round(sum(data_length/1024/1024),2),'MB') as data from t ...
- mysqldump: Got error: 1135: Can't create a new thread (errno 11); if you are not out of available memory, you can consult the manual for a possible OS-dependent bug when trying to connect 解决办法
在进行数据库备份的时候发现服务器报 mysqldump: Got error: 1135: Can't create a new thread (errno 11); if you are not o ...
- 【转】hexo博客图片问题
1.首先确认_config.yml 中有 post_asset_folder:true. Hexo 提供了一种更方便管理 Asset 的设定:post_asset_folder 当您设置post_as ...
- 程序运行bug查看
1.左击计算机进入管理,点击windows日志,查看程序信息. 可以方便看到报错信息.
- MySQL 初识01
最近开始学习MySQL 所以将这两天所学习到的知识简单小结一下 1.status 显示数据库信息 2.数据类型: a.字符串: char(m):固定长度的字符,最多255个字符: varchar(m) ...
- 初学者学习python2还是python3?
如果你是一个初学者,或者你以前接触过其他的编程语言,你可能不知道,在开始学习python的时候都会遇到一个比较让人很头疼的问题:版本问题!!是学习python2 还是学习 python3 ?这是非常让 ...
- (转) linux I/O优化 磁盘读写参数设置
关于页面缓存的信息,可以用cat /proc/meminfo 看到.其中的Cached 指用于pagecache的内存大小(diskcache-SwapCache).随着写入缓存页,Dirty 的值会 ...
- Android 实现异步加载图片
麦洛开通博客以来,有一段时间没有更新博文了.主要是麦洛这段时间因项目开发实在太忙了.今天周六还在公司加班,苦逼程序猿都是这样生活的. 今天在做项目的时候,有一个实现异步加载图片的功能,虽然比较简单但还 ...
- 偶遇RandomAccessFile
一.前言 本来在研究NIO,别人举的栗子里面,看到一个RandomAccessFile类,之前没见过,就去看了一下,现将相关内容记录如下 二.正文 RandomAccessFile直接继承自Objec ...
- Dubbo 项目与传统项目
1.什么是传统工程 单工程 MVC 架构 控制层通过调用服务层完成业务逻辑处理 业务层调用持久层进程数据操作 2.什么是分布式工程 将传统项目的单工程结构,拆分成多工程 一般会有这几个工程: 父工程: ...