Calling UNIX command from Cocoa

  • Ok., I am sure I have seen one but can't seem to find it. I need an
    Open Source class to call a command line program with a couple of
    arguments. Does any one know of any and where I can find one?

    Thanks.
  • On Oct 16, 2008, at 3:09 PM, development2 wrote:

    > Ok., I am sure I have seen one but can't seem to find it. I need an
    > Open Source class to call a command line program with a couple of
    > arguments. Does any one know of any and where I can find one?

    Do you need open source to see the source, or just so it's available
    for you to use.

    I ask because such a class is built into Cocoa, although it's closed
    source: NSTask.

    I suppose, if you really need to see source code, there's probably a
    version of NSTask in GnuStep.

    Cheers,
    Ken
  • Calling a command line function can be handled with plain old C as
    well. Look at the exec() function set.

    frm

    Franklin Marmon
    <agathezol...>
    GTalk: <agathezol...>

    On Oct 16, 2008, at 2:14 PM, Ken Thomases wrote:

    > On Oct 16, 2008, at 3:09 PM, development2 wrote:
    >
    >> Ok., I am sure I have seen one but can't seem to find it. I need an
    >> Open Source class to call a command line program with a couple of
    >> arguments. Does any one know of any and where I can find one?
    >
    > Do you need open source to see the source, or just so it's available
    > for you to use.
    >
    > I ask because such a class is built into Cocoa, although it's closed
    > source: NSTask.
    >
    > I suppose, if you really need to see source code, there's probably a
    > version of NSTask in GnuStep.
    >
    > Cheers,
    > Ken
  • Yeah I know about NSTask, I just can't get it too work correctly.

    On Oct 16, 2008, at 2:14 PM, Ken Thomases wrote:

    > On Oct 16, 2008, at 3:09 PM, development2 wrote:
    >
    >> Ok., I am sure I have seen one but can't seem to find it. I need an
    >> Open Source class to call a command line program with a couple of
    >> arguments. Does any one know of any and where I can find one?
    >
    > Do you need open source to see the source, or just so it's available
    > for you to use.
    >
    > I ask because such a class is built into Cocoa, although it's closed
    > source: NSTask.
    >
    > I suppose, if you really need to see source code, there's probably a
    > version of NSTask in GnuStep.
    >
    > Cheers,
    > Ken
    >
    >
  • On Oct 16, 2008, at 3:03 PM, development2 wrote:
    > Yeah I know about NSTask, I just can't get it too work correctly.

    NSTask is one heck of a lot easier to use than any of the lower level
    calls except, maybe, popen().

    It definitely works, too.

    What are the failure symptoms?

    b.bum
  • On Oct 17, 2008, at 00:08, Bill Bumgarner wrote:

    > On Oct 16, 2008, at 3:03 PM, development2 wrote:
    >> Yeah I know about NSTask, I just can't get it too work correctly.
    >
    > NSTask is one heck of a lot easier to use than any of the lower
    > level calls except, maybe, popen().

    It took me also quite a while to get it working properly. Most
    examples were just too simplistic.

    By no means saying this is perfect ....but it seems to work:

      http://github.com/tcurdt/feedbackreporter/tree/master/Sources/Main/Command.
    m


    cheers
    --
    Torsten
  • Am 17.10.2008 um 00:03 Uhr schrieb development2:

    > Yeah I know about NSTask, I just can't get it too work correctly.

    This might help:

    http://www.harmless.de/cocoa-code.php#shellwrapper

    Andreas
  • Without knowing more specifics, I am struggling to find why one would need a
    full-blown class just to invoke a command.  At the simplest, one could use
    the system(3) call, or the exec/spawn/fork/popen families depending on what
    you need. It is of course, possible to wrap up something fancy like using an
    NSDictionary to represent commandline arguments, etc. etc. but that is
    usually overkill, no?

    On 10/16/08 13:09 , "development2" <development2...> wrote:

    > Ok., I am sure I have seen one but can't seem to find it. I need an
    > Open Source class to call a command line program with a couple of
    > arguments. Does any one know of any and where I can find one?
    >
    > Thanks.
  • On Fri, Oct 17, 2008 at 4:14 PM, Aurora Phoenix
    <aurora.phoenix.draco...> wrote:
    >
    > Without knowing more specifics, I am struggling to find why one would need a
    > full-blown class just to invoke a command.

    Because it is easier to use, and it handles many edge cases. Also, you
    are over-estimating the overhead of using a "full-blown class"; it is
    lost in the noise when compared to the actual process
    creation/launching.

    > At the simplest, one could use
    > the system(3) call

    system() (or popen) will get a shell involved, thereby adding unneeded
    complexity.

    > , or the exec/spawn/fork/popen families depending on what
    > you need.

    Using NSTask *is* using the exec/spawn/fork families, just wrapped in
    a cleaner interface.

    > It is of course, possible to wrap up something fancy like using an
    > NSDictionary to represent commandline arguments, etc. etc. but that is
    > usually overkill, no?

    It is only overkill because NSTask already exists. :)

    --
    Clark S. Cox III
    <clarkcox3...>