【发布时间】:2025-12-16 07:05:03
【问题描述】:
我正在寻找有关我正在制作的程序的帮助。 我创建一个 *.sh 文件如下:
SVN_StatGenAppDelegate.h:
NSWindow *window;
NSTask *touch;
NSArray *touchArguments;
NSString *svnURLStr;
NSString *SVNStatStr;
NSString *destDirStr;
SVN_StatGenApplDelegate.m:
NSString *locationStr = [NSString stringWithFormat:@"%@/exec.sh", destDirStr];
NSLog(@"%@", locationStr);
touch = [[NSTask alloc] init];
[touch setLaunchPath:@"/usr/bin/touch"];
touchArguments = [NSArray arrayWithObjects:locationStr, nil];
[touch setArguments:touchArguments];
[touch launch];
这行得通,我在我用 destDirStr 创建的位置创建了一个名为 exec.sh 的文件。 现在是我的下一个问题,我需要让该文件填写以下内容:
svn co http://repo.com/svn/test C:\users\twan\desktop\pres\_temp
cd C:\users\twan\desktop\pres\_temp
svn log -v --xml > logfile.log
copy C:\users\twan\desktop\statsvn.jar C:\users\twan\desktop\pres\_temp
cd ..
java -jar _temp\statsvn.jar C:\users\twan\desktop\pres\_temp/logfile.log C:\users\twan\desktop\pres\_temp
rmdir /s /Q _temp
实际的想法是这个脚本被写入 sh 文件,所有的 _temp 和其他位置都被我从 textfields 等获取的 vars 替换。
所以 c:\users\twan\desktop\pres_temp 将是一个名为 tempDirStr 的变量,我从我的输入字段中获得。
(我知道这些命令和位置是基于 Windows 的,我和一个朋友一起做这件事,他做了一个 .net 对应的应用程序。
你们能帮帮我吗?:D 提前致谢!
【问题讨论】:
-
为什么不能直接使用
-[NSString writeToFile:atomically:encoding:error:]? -
是的,你根本不需要 NSTask。
-
我要去使用那个 writeToFile 方法,也许这就是我要找的。我是可可(和objective-c)的新手,所以..我只是想提取一些东西;P 感谢您的回复,我会检查一下