PDA

View Full Version : Programming: Run app via programming command




slooksterPSV
Jul 7, 2006, 05:05 PM
Is there anyways to make your application run an external application? Ok so I want to make a lightweight compiler for C, C++, HTML, PHP (the latter 2 I know don't need a compiler, but still). Is there anyways I can run an application from within an application? Mainly gcc and/or g++ ?
Is there a way to do it with Objective-C something like this?

[NSApplication runApplication: @"/usr/bin/gcc"]



ham_man
Jul 7, 2006, 05:12 PM
Is there anyways to make your application run an external application? Ok so I want to make a lightweight compiler for C, C++, HTML, PHP (the latter 2 I know don't need a compiler, but still). Is there anyways I can run an application from within an application? Mainly gcc and/or g++ ?
Is there a way to do it with Objective-C something like this?

[NSApplication runApplication: @"/usr/bin/gcc"]
XCode does it. SuperDuper does it with psync. I don't see why you couldn't do it. You may need to dig for the proper classes and whatnot, but it is possible.

*shrugs*

robbieduncan
Jul 7, 2006, 05:14 PM
Take a look at NSTask (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSTask_Class/Reference/Reference.html#//apple_ref/doc/uid/20000317).

There is a step-by-step example of how to wrap a command line app here (http://cocoadevcentral.com/articles/000025.php).

slooksterPSV
Jul 8, 2006, 12:03 AM
Here it is, I got it to work like this:
... //code up here
NSString *launchProg = @"/usr/bin/gcc";

NSArray *parameters;
parameters = [NSArray arrayWithObjects: @"/Users/sbarn/Programming/test.c", @"-o", @"/Users/sbarn/Programming/MyLongApp", nil];

NSTask *nts = [[NSTask alloc] init];
[nts setLaunchPath: launchProg];
[nts setArguments: parameters];
[nts launch];
... //more code down here

Soulstorm
Jul 8, 2006, 01:01 AM
couldn't this be done using the system() function in C?

slooksterPSV
Jul 8, 2006, 07:59 AM
couldn't this be done using the system() function in C?
It could, but I want to do things in pure Obj-C & Cocoa where possible.

Soulstorm
Jul 8, 2006, 10:11 AM
It could, but I want to do things in pure Obj-C & Cocoa where possible.
Actually, using the system() function IS pure Objective C. Objective C is a pure superset of C, so every command valid in C, is pure Objective C too. Plus, it's easier to do it that way, so why go into your toilet by visiting Italy first?

slooksterPSV
Jul 8, 2006, 08:21 PM
Actually, using the system() function IS pure Objective C. Objective C is a pure superset of C, so every command valid in C, is pure Objective C too. Plus, it's easier to do it that way, so why go into your toilet by visiting Italy first?
I like using the SmallTalk Syntax with [ ], it just makes things easier and more readable.

bousozoku
Jul 8, 2006, 09:04 PM
Actually, using the system() function IS pure Objective C. Objective C is a pure superset of C, so every command valid in C, is pure Objective C too. Plus, it's easier to do it that way, so why go into your toilet by visiting Italy first?

You can also do it using the various exec* and fork* functions, which is the typical UNIX way.