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,543
305
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"]
 

ham_man

macrumors 68020
Jan 21, 2005
2,265
0
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*
 

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,543
305
Nowheresville
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

macrumors 68000
Feb 1, 2005
1,887
1
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?
 

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,543
305
Nowheresville
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.
 

bousozoku

Moderator emeritus
Jun 25, 2002
15,726
1,895
Lard
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.