Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,546
309
Nowheresville
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"]
 
slooksterPSV said:
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*
 
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
 
slooksterPSV said:
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?
 
Soulstorm said:
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.
 
Soulstorm said:
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.