Re: Dumping input to NSTask
Re: Dumping input to NSTask
- Subject: Re: Dumping input to NSTask
- From: "Louis C. Sacha" <email@hidden>
- Date: Wed, 14 Jul 2004 17:10:30 -0700
Hello...
If you are not creating your own input and output pipes or file
handles, then that could be the problem. If you have created an
NSPipe instance to be used as the input, the write end is close when
the task is launched, so you need to send the data before you launch
the task.
Running this kind of task would go something like this:
1) Create the instance of NSTask used for running the task, and set
the basic things like path, arguments, etc...
2) Create input and output pipes if you need to send input or get
output, and use the NSTask setInput: and setOutput: instance methods
so that they will be connected to your task.
3) If you need to send input get the NSFileHandle from the NSPipe for
the input, and write your data to it.
4) Launch the task.
5) Wait until the task finishes or check for available data using a
timer, and get your output from the output pipes's NSFileHandle.
6) When the task is finished, you can check the result code from the
tool using the terminationStatus instance method, but you need to be
sure the task is actually done (using isRunning if you didn't use
waitUntilExit) before you call it.
Hope that helps,
Louis
Greetings -
I'm trying to execute a program via NSTask that works normally by launching,
grabbing input, and then printing output and executing. Typically, I'd
create the input as a text file, then run the program like:
cat inputFile | /path/to/my/program
In trying to do that via NSTask, I've created the input as a string, then
use the string to create an NSData (using UTF8), and then send that through
the task's standard input file handle. The problem is that the task hangs -
it seems to be waiting for the input to terminate, but if I close the file
handle, I crash with invalid memory access.
Any suggestions?
JT
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.