Search Results

Search found 19 results on 1 pages for 'nstask'.

Page 1/1 | 1 

  • NSTask executed only once

    - by Eimantas
    I'm having trouble executing different NSTask's. Same launchPath, different arguments. I have a class who's instances administer own NSTask objects and depending on arguments those instances were initialized with - dependent NSTask object is being created. I have two initializers: // Method for finished task - (void)taskFinished:(NSNotification *)aNotification { [myTask release]; myTask = nil; [self createTask]; } // Designated initializer - (id) init { self = [super init]; if (self != nil) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(taskFinished:) name:NSTaskDidTerminateNotification object:nil]; [self createTask]; } return self; } // Convenience initializer - (id)initWithCommand:(NSString *)subCommand { self = [self init]; if (self) { [self setCommand:subCommand]; } return self; } And here 's the createTask method: - (void)createTask { // myTask is a property defined as NSTask* myTask = [[NSTask alloc] init]; [myTask setLaunchPath:@"/usr/bin/executable"]; } Say I have 3 buttons. Each one creates different class instance with different NSTask objects. But problem is that only first one gets executed. The second ones does not even triger "click" event (via target-action). I think it could be cause of launchPath I'm trying to use, 'cause simple /bin/ls works fine. The same command in terminal has 0 return value (i.e. all is fine). Any guides or gotchas are much appreciated.

    Read the article

  • NSTask Tail -f Using objective C

    - by Bach
    I need to read the last added line to a log file, in realtime, and capture that line being added. Something similar to Tail -f. So my first attempt was to use Tail -f using NSTask. I can't see any output using the code below: NSTask *server = [[NSTask alloc] init]; [server setLaunchPath:@"/usr/bin/tail"]; [server setArguments:[NSArray arrayWithObjects:@"-f", @"/path/to/my/LogFile.txt",nil]]; NSPipe *outputPipe = [NSPipe pipe]; [server setStandardInput:[NSPipe pipe]]; [server setStandardOutput:outputPipe]; [server launch]; [server waitUntilExit]; [server release]; NSData *outputData = [[outputPipe fileHandleForReading] readDataToEndOfFile]; NSString *outputString = [[[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding] autorelease]; NSLog (@"Output \n%@", outputString); I can see the output as expected when using: [server setLaunchPath:@"/bin/ls"]; How can i capture the output of that tail NSTask? Is there any alternative to this method, where I can open a stream to file and each time a line is added, output it on screen? (basic logging functionality)

    Read the article

  • [Cocoa] NSTask string encoding problem

    - by ryyst
    Hi, In my program, I'm grep-ing via NSTask. For some reason, sometimes I would get no results (even though the code was apparently the same as the command run from the CLI which worked just fine), so I checked through my code and found, in Apple's documentation, that when adding arguments to an NSTask object, "the NSTask object converts both path and the strings in arguments to appropriate C-style strings (using fileSystemRepresentation) before passing them to the task via argv[]" (snip). The problem is that I might grep terms like "Río Gallegos". Sadly (as I checked with fileSystemRepresentation), that undergoes the conversion and turns out to be "RiÃÅo Gallegos". How can I solve this? -- Ry

    Read the article

  • NSTask Launch causing crash

    - by tripskeet
    Hi, I have an application that can import an XML file through this terminal command : open /path/to/main\ app.app --args myXML.xml This works great with no issues. And i have used Applescript to launch this command through shell and it works just as well. Yet when try using Cocoa's NSTask Launcher using this code : NSTask *task = [[NSTask alloc] init]; [task setLaunchPath:@"/usr/bin/open"]; [task setCurrentDirectoryPath:@"/Applications/MainApp/InstallData/App/"]; [task setArguments:[NSArray arrayWithObjects:[(NSURL *)foundApplicationURL path], @"--args", @"ImportP.xml", nil]]; [task launch]; the applications will start up to the initial screen and then crash when either the next button is clicked or when trying to close the window. Ive tried using NSAppleScript with this : NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"tell application \"Terminal\" do script \"open /Applications/MainApp/InstallData/App/Main\\\\ App.app\" end tell"]; NSDictionary *errorInfo; [script executeAndReturnError:&errorInfo]; This will launch the program and it will crash as well and i get this error in my Xcode debug window : 12011-01-04 17:41:28.296 LaunchAppFile[4453:a0f] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper LaunchAppFile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers. So with research i came up with this : NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"do shell script \"arch -i386 osascript /Applications/MainApp/InstallData/App/test.scpt\""]; NSDictionary *errorInfo; [script executeAndReturnError:&errorInfo]; But this causes the same results as the last command. Any ideas on what causes this crash?

    Read the article

  • Problems with NSTask in OS X 10.6 Snow Leopard

    - by kubi
    Has anyone else seen or heard of any issues with NSTask in 10.6? This code worked fine yesterday, and is not working today. NSTask *task = [converter task]; [task waitUntilExit]; NSLog(@"Task did complete"); The task does what it's supposed to do (I checked the output and it's fine), but the program will wait indefinitely at the waitUntilExit method. I have a few unit tests that use similar code, they all had passed previously, but as of yesterday, they are no longer working.

    Read the article

  • Can NSTask safely be used outside the main thread?

    - by neoneye
    Yesterday I read somewhere that NSTask isn't thread safe and that bothers me a lot, because I'm running a NSTask within a NSThread and is so far not experiencing any threading issues with it. My code is organized like this A: main thread -> B: worker thread -> C: worker task C: The worker task is a commandline program. B: The worker thread can start/stop the worker task and send it commands. A: The main thread can send commands to the worker thread. If NSTask is supposed to be used only within the main thread, then I'm considering moving the NSTask start/stop code to the main thread, just to prevent possible threading issues. Can NSTask be used outside the main thread? And if not then what may be the threading issues with NSTask?

    Read the article

  • Terminating suspended NSTask.

    - by Jef
    Hi, If I terminate (or interrupt) a suspended NSTask, then it still shows up in activity monitor. It isn't running because the CPU is 0% but it's still taking up memory. Is there a work around?

    Read the article

  • NSTask or NSThread?

    - by Ben Packard
    I have some code that is attached to an NSTimer. Around 5 times every second, it interacts with another application (by emulating keystrokes) and when appropriate spits out an NSNotification, that is handled by another piece of code. While the timer code is running, the UI is unresponsive, so I can't include a 'stop' button that halts the timer. How should I handle this? A separate process (NSTask right?) or thread? Remember that at unpredictable times, the timer code will need to send some info back for processing. Thanks.

    Read the article

  • How to open a document using an application launched via NSTask?

    - by zneak
    Hello world, I've grown tired of the built-in open Mac OS X command, mostly because it runs programs with your actual user ID instead of the effective user ID; this results in the fact sudo open Foo opens Foo with its associated application with your account instead of the root account, and it annoys me. So I decided to make some kind of replacement. So far I've been successful: I can open any program under the open -a or open -b fashion, and support optionally waiting. I'm using NSTask for that purpose. However, I'd like to be able to open documents too. As far as I can see, you need to use NSWorkspace for that, but using NSWorkspace to launch programs results in them being launched with your account's credentials instead of your command line program's credentials. Which is precisely what the default open tool does, and precisely what I don't want. So, how can I have a program request that another program opens a document without using NSWorkspace? From the NSTask object, I can have the process ID, but that's about it.

    Read the article

  • sending control+c (SIGINT) to NSPIPE in objective-c

    - by Ron
    Hello, I am trying to terminate an openvpn task, spawned via NSTask. My question: Should I send ctrl+c (SIGINT) to the input NSPipe for my NSTask? inputPipe = [NSPipe pipe]; taskInput = [inputPipe fileHandleForWriting]; NSString dataString = @"\cC"; [taskInput writeData:[dataString dataUsingEncoding: [NSString defaultCStringEncoding]]]; Alternatively, I was thinking about using kill( pid, SIGINT ); but it would be much more complicated since the process ID has to be determined via a detour ([task processIdentifier] does not help here) - the original NSTask calls: /bin/bash -c sudo -S | mypassword .... That's not nice, I know but it is only called once and the sudo password has been entered in that case already. thanks for any suggestions/opinions/etc. Ron

    Read the article

  • [Cocoa] Can't find leak in my code.

    - by ryyst
    Hi, I've been spending the last few hours trying to find the memory leak in my code. Here it is: NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; expression = [expression stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]; // expression is an NSString object. NSArray *arguments = [NSArray arrayWithObjects:expression, [@"~/Desktop/file.txt" stringByExpandingTildeInPath], @"-n", @"--line-number", nil]; NSPipe *outPipe = [[NSPipe alloc] init]; NSTask *task = [[NSTask alloc] init]; [task setLaunchPath:@"/usr/bin/grep"]; [task setArguments:arguments]; [task setStandardOutput:outPipe]; [outPipe release]; [task launch]; NSData *data = [[outPipe fileHandleForReading] readDataToEndOfFile]; [task waitUntilExit]; [task release]; NSString *string = [[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding]; string = [string stringByReplacingOccurrencesOfString:@"\r" withString:@""]; int linesNum = 0; NSMutableArray *possibleMatches = [[NSMutableArray alloc] init]; if ([string length] > 0) { NSArray *lines = [string componentsSeparatedByString:@"\n"]; linesNum = [lines count]; for (int i = 0; i < [lines count]; i++) { NSString *currentLine = [lines objectAtIndex:i]; NSArray *values = [currentLine componentsSeparatedByString:@"\t"]; if ([values count] == 20) [possibleMatches addObject:currentLine]; } } [string release]; [pool release]; return [possibleMatches autorelease]; I tried to follow the few basic rules of Cocoa memory management, but somehow there still seems to be a leak, I believe it's an array that's leaking. It's noticeable if possibleMatches is large. You can try the code by using any large file as "~/Desktop/file.txt" and as expression something that yields many results when grep-ing. What's the mistake I'm making? Thanks for any help! -- Ry

    Read the article

  • Download file with progress bar in cocoa?

    - by happyCoding25
    Hello, I need to have a progress bar that responds to the percent complete of a download in cocoa. I think this might use things like NSProgressindicator and possibly NSTask. I'm not sure if theres an "official" method to download file in cocoa because up until now I just used curl with NSTask. Thanks for any replies.

    Read the article

  • Cocoa: Using UNIX based commands to write a file

    - by BryCry
    I'm looking for help with a program im making. I create a *.sh file as follows: SVN_StatGenAppDelegate.h: NSWindow *window; NSTask *touch; NSArray *touchArguments; NSString *svnURLStr; NSString *SVNStatStr; NSString *destDirStr; SVN_StatGenApplDelegate.m: NSString *locationStr = [NSString stringWithFormat:@"%@/exec.sh", destDirStr]; NSLog(@"%@", locationStr); touch = [[NSTask alloc] init]; [touch setLaunchPath:@"/usr/bin/touch"]; touchArguments = [NSArray arrayWithObjects:locationStr, nil]; [touch setArguments:touchArguments]; [touch launch]; This works, i get a file called exec.sh created in the location i craete with the destDirStr. Now is my next question, i need to get that file filled with the following: svn co http://repo.com/svn/test C:\users\twan\desktop\pres\_temp cd C:\users\twan\desktop\pres\_temp svn log -v --xml > logfile.log copy C:\users\twan\desktop\statsvn.jar C:\users\twan\desktop\pres\_temp cd .. java -jar _temp\statsvn.jar C:\users\twan\desktop\pres\_temp/logfile.log C:\users\twan\desktop\pres\_temp rmdir /s /Q _temp The actual idea is that this script is written into the sh file, and all the _temp and other locations are replaced by the vars i get from textfields etc. so c:\users\twan\desktop\pres_temp would be a var called tempDirStr that i get from my inputfields. (i know these cmomands and locations are windows based, im doing this with a friend and he made a .net counterpart of the application. Can you guys help me out?:D thanks in advance!

    Read the article

  • Getting output of a shell script in Cocoa

    - by Tristan Seifert
    Is there a way that lets me run a shell script, and display the output in an NSTextView? I do not want any input from the user to the shell script at all, since is is just called to compile a buch of files. The shell script part works fine so far, but I just can't figure out how to run it and show the output in an NSTextView. I know a shell script can be run using system() and NSTask, but how do I get it's output into an NSTextView?

    Read the article

  • Invoking external shell application through RubyCocoa

    - by Shyam
    Hi, How would I invoke an external application through the RubyCocoa bridge? I read something about NSTask, yet I have no idea how this should be translated in RubyCocoa. My goal is to have an IB_action to trigger a method which will run a terminal application with some parameters, i.e. ls -p $mydir, where mydir comes from an IB_outlet such as an Textfield. Any directions or help would be greatly appreciated!

    Read the article

  • Code Signing Services

    - by bogdan
    I'm developing a System Preference Pane that runs a background application. I'm planning on codesigning the background application and I'll be using the kill flag of codesign (http://gemma.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/codesign.1.html). From my understanding, this kill flag will not allow the background application to be run if it's signature doesn't match. My problem with this approach is that it doesn't provide any feedback to the user and, for somewhat reason, the application gets corrupted, it will refuse to launch without any information. I'd like to use the Code Signing Service from the System Preference Pane to check the validity of the background application. However, I couldn't find how to use it to check the validity of an external file. Is this possible using the Code Signing Service or should I NSTask codesign directly? My application is targeted for 10.6 so it doesn't matter which I use. Thank you!

    Read the article

  • iOS get file size on disk

    - by F2_CMD
    I'm trying to get the size on disk of a file in iOS using Objective C. As of now I've been able to get the actual size of the file and other file information using NSFileManager and then getting the attributes attributesOfItemAtPath:error but not the size on disk. I also tried getting the file size from struct stat but again it doesn't give me size on disk.I tried using NSTask to make a call to du -h but iOS didn't allow me to fork other processes. Any ideas are welcome :) I know this questions is similar to many others but the difference is that I'm trying to do this in iOS and most of the methods used in other systems don't work here. Thanks

    Read the article

  • Mac OS X: Getting detailed process information (specifically its launch arguments) for arbitrary run

    - by Jasarien
    I am trying to detect when particular applications are launched. Currently I am using NSWorkspace, registering for the "did launch application" notification. I also use the runningApplications method to get apps that are currently running when my app starts. For most apps, the name of the app bundle is enough. I have a plist of "known apps" that I cross check with the name of that passed in the notification. This works fine until you come across an app that acts as a proxy for launching another application using command line arguments. Example: The newly released Portal on the Mac doesn't have a dedicated app bundle. Steam can create a shortcut, which serves as nothing more than to launch the hl2_osx app with the -game argument and portal as it's parameter. Since more Source based games are heading to the Mac, I imagine they'll use the same method to launch, effectively running the hl2_osx app with the -game argument. Is there a nice way to get a list of the arguments (and their parameters) using a Cocoa API? NSProcessInfo comes close, offering an `-arguments' method, but only provides information for its own process... NSRunningApplication offers the ability to get information about arbitrary apps using a PID, but no command line args... Is there anything that fills the gap between the two? I'm trying not to go down the route of spawning an NSTask to run ps -p [pid] and parsing the output... I'd prefer something more high level.

    Read the article

  • DRY Authenticated Tasks in Cocoa (with distributed objects)

    - by arbales
    I'm kind of surprise/infuriated that the only way for me to run an authenticated task, like perhaps sudo gem install shi*t, is to make a tool with pre-written code. I'm writing a MacRuby application, which doesn't seem to expose the KAuthorization* constants/methods. So.. I learned Cocoa and Objective-C. My application creates a object, serves it and calls the a tool that elevates itself and then performs a selector on a distributed object (in the tool's thread). I hoped that the distributed object's methods would evaluated inside the tool, so I could use delegation to create "privileged" tasks. If this won't work, don't try to save it, I just want a DRY/cocoa solution. AuthHelper.m //AuthorizationExecuteWithPrivileges of this. AuthResponder* my_responder = [AuthResponder sharedResponder]; // Gets the proxy object (and it's delegate) NSString *selector = [NSString stringWithUTF8String:argv[3]]; NSLog(@"Performing selector: %@", selector); setuid(0); if ([[my_responder delegate] respondsToSelector:NSSelectorFromString(selector)]){ [[my_responder delegate] performSelectorOnMainThread:NSSelectorFromString(selector) withObject:nil waitUntilDone:YES]; } RandomController.m - (void)awakeFromNib { helperToolPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/AuthHelper"]; delegatePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/ABExtensions.rb"]; AuthResponder* my_responder = [AuthResponder initAsService]; [my_responder setDelegate:self]; } -(oneway void)install_gems{ NSArray *args = [NSArray arrayWithObjects: @"gem", @"install", @"sinatra", nil]; [NSTask launchedTaskWithLaunchPath:@"/usr/bin/sudo" arguments:args]; NSLog(@"Ran AuthResponder.delegate.install_gems"); // This prints. } ... other privileges tasks. "sudo gem update --system" for one. I'm guessing the proxy object is performing the selector in it's own thread, but I want the current (privileged thread) to do it so I can use sudo. Can I force the distributed object to evaluate the selector on the tool's thread? How else can I accomplish this dryly/cocoaly?

    Read the article

1