discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Running a command using NSTask


From: Csanyi Pal
Subject: Re: Running a command using NSTask
Date: Sun, 21 Nov 2010 11:58:46 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Hi Richard,

Richard Frith-Macdonald <richard.frith-macdonald@brainstorm.co.uk>
writes:

> On 21 Nov 2010, at 08:34, Csanyi Pal wrote:

>> [code]
>>  [DPSetBit0 setLaunchPath: @"/usr/local/bin/DPSetBit0"];

> Well, the hard-coded launch path is not portable, and would definitely
> be wrong on ms-windows for instance, so that might be an issue. 
>
> A portable way to determine the correct path to an executable might be
> to use NSSearchPathForDirectoriesInDomains() to get a list of the
> directories the program might be in, then use
> [NSString-stringByAppendingPathComponent:] to append your program name
> to each directory in turn, and use
> [NSFileManager-isExecutableFileAtPath:] to check each to see if the
> program is there. 
>
> Alternatively, you could use the GNUstep extension
> [NSTask+launchPathForTool:] (declared in
> GNUstepBase/NSTask+GNUstepBase.h) method to do all that for you. 
>
> Assuming that you have the correct path to the executable, then I
> guess the thing to do is check the return status of the subtask. 
> Call [NSTask-waitUntilExit] to wait for the task to exit, then call
> [NSTask-terminationStatus] and perhaps [NSTask-terminationReason] to
> see how/why the subtask terminated. 

I modified the code:

[code]
- (void) DPbitSetReset: (id)sender
{
  NSSound *DPbitReset = [NSSound soundNamed: @"DPbitReset.wav"];
  NSSound *DPbitSet = [NSSound soundNamed: @"DPbitSet.wav"];

  NSTask *DPSetBit0 = [[NSTask alloc] init];
  (NSString*) launchPathForTool: (NSString*)DPSetBit0;

  // Whether the button state is 1 or 0?
  if ([sender state] == 1)
     {
       // Play the bit set sound
       [DPbitSet play];

       // Which bit to set on Data Port?
       switch ([sender tag])
         {
         case 110: // DPb0sr
           [DPSetBit0 launch];
           [NSTask-waitUntilExit];
           [NSTask-terminationStatus];
           [NSTask-terminationReason];
           [DPSetBit0 release];
           [StatLine setStringValue: @"Write logical 1 to the data port bit 
0."];
           break;
[/code]

but when I try to compile it I get errors:

MainController.m: In function ‘-[MainController DPbitSetReset:]’:
MainController.m:124: error: ‘launchPathForTool’ undeclared (first use
in this function) 
MainController.m:124: error: (Each undeclared identifier is reported
only once 
MainController.m:124: error: for each function it appears in.)
MainController.m:124: error: expected ‘;’ before ‘:’ token
MainController.m:139: error: expected ‘:’ before ‘-’ token
MainController.m:140: error: expected ‘:’ before ‘-’ token
MainController.m:141: error: expected ‘:’ before ‘-’ token
make[3]: *** [obj/LPT_Interface.obj/MainController.m.o] Error 1
make[2]: *** [internal-app-run-compile-submake] Error 2
make[1]: *** [LPT_Interface.all.app.variables] Error 2
make: *** [internal-all] Error 2

What is the problem in my code?
How can I fix it?
Maybe I must to include GNUstepBase.h in to MainController.m?

Any advices will be appreciated!

-- 
Regards, Paul Chany
<http://sourceforge.net/projects/lptinterface/>
<http://savannah.nongnu.org/projects/lpt-interface/>
<http://csanyi-pal.info>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]