PCDVD數位科技討論區
PCDVD數位科技討論區   註冊 常見問題 標記討論區為已讀

回到   PCDVD數位科技討論區 > 其他群組 > 疑難雜症區
帳戶
密碼
 

回應
 
主題工具
Goemon
*停權中*
 
Goemon的大頭照
 

加入日期: Dec 2016
文章: 23
問一個關於 Objective-C 與 C 的問題

例如我編譯的 xxx.app 底下有兩個文件例如 cat 與 readme.txt
我打算在yyyy/xxx.app程式啟動的時候執行
$ yyyy/xxx.app/ls -l /yyyy/xxx.app/readme.txt

yyyy 是隨機數值

在 Objective-C 上該怎麼寫


在 C 上面執行shell我目前知道用

mianbundle Patch = yyyy

file_ls = mianbundle Patch + "/ls"
file_readme = mianbundle Patch + "/readme.txt"

代碼:
    pid_t pid;
    char *argv[] = {
        file_ls,
        "-l",
        file_readme,
        NULL
    };


但是這個 mianbundle Patch 我不知道怎麼寫
     
      

此文章於 2016-12-25 10:41 PM 被 Goemon 編輯.
舊 2016-12-25, 10:40 PM #1
回應時引用此文章
Goemon離線中  
Goemon
*停權中*
 
Goemon的大頭照
 

加入日期: Dec 2016
文章: 23
那換個方式問好了

代碼:
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSLog(@“\n\App Path: %@", bundlePath);

NSString *exec_launch = [[NSBundle mainBundle] pathForResource:@"launch" ofType:@""];
NSLog(@"\n\app Path: %@", exec_launch);


換成 C++ 寫法 該怎麼寫
 
舊 2016-12-26, 12:53 AM #2
回應時引用此文章
Goemon離線中  
打工吧魔王大人
*停權中*
 
打工吧魔王大人的大頭照
 

加入日期: May 2014
您的住址: 某個不大不小的島
文章: 628
不明覺厲
只好頂帖.
舊 2016-12-26, 06:03 AM #3
回應時引用此文章
打工吧魔王大人離線中  
Goemon
*停權中*
 
Goemon的大頭照
 

加入日期: Dec 2016
文章: 23
引用:
作者打工吧魔王大人
不明覺厲
只好頂帖.


感謝頂帖, 我寫好了.

代碼:
#include "CoreFoundation/CoreFoundation.h"

    // get app mainBundle
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef resourcesURL = CFBundleCopyBundleURL(mainBundle);
    CFStringRef str = CFURLCopyFileSystemPath( resourcesURL, kCFURLPOSIXPathStyle );
    CFRelease(resourcesURL);
    char* app_bundle  = malloc(sizeof(char) * 1024);

    CFStringGetCString( str, app_bundle, FILENAME_MAX, kCFStringEncodingASCII );
    CFRelease(str);
 
    printf("App mainBundle: %s\n", app_bundle);

    // get app mainBundle .app/launch
    const char *file_launch = "/launch";
    char *exec_launch;
    exec_launch = malloc(strlen(app_bundle) + strlen(file_launch) + 1);
    
    strcpy(exec_launch, app_bundle);
    strcat(exec_launch, file_launch);
    
    printf("exec_launch: %s\n", exec_launch);
舊 2016-12-26, 07:50 AM #4
回應時引用此文章
Goemon離線中  


回應


POPIN
主題工具

發表文章規則
不可以發起新主題
不可以回應主題
不可以上傳附加檔案
不可以編輯您的文章

vB 代碼打開
[IMG]代碼打開
HTML代碼關閉



所有的時間均為GMT +8。 現在的時間是07:59 AM.


vBulletin Version 3.0.1
powered_by_vbulletin 2024。