• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTask not using arguments?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTask not using arguments?


  • Subject: Re: NSTask not using arguments?
  • From: Sherm Pendley <email@hidden>
  • Date: Thu, 24 Feb 2005 16:56:08 -0500

On Feb 24, 2005, at 7:27 AM, <email@hidden> wrote:

I have an NSTask set up to take 4 arguments, the first a switch "-b", the second is an absolute path to some files, the third is the output redirection operator ">" and the last is another absolute path with a desired filename. The task is supposed to take the files in the first directory and redirect the output to a checksum file described in the second path.

Let me first say that I went into Terminal to use the same exact UNIX app, using the same exact values as my application set in the standard arguments array, and it worked fine. It created the desired checksum file.

But when I run my app, it's almost acting like it's not accepting or not using the second, third, and fourth arguments. After "processing", I get the following errors:

/Users/james/DevBox/AudioConverter/build/AudioConverter.app/Contents/ Resources/Binaries/bin/md5sum: /Users/james/Desktop/test/*.shn: No such file or directory.

md5sum: >: No such file or directory
md5sum: /Users/james/Desktop/md5sum.md5: No such file or directory.

Essentially, there are two things you need to do manually here, both of which the command shell are doing for you when you enter the command manually.


The first is file name globbing. That's a shell function - when you pass a file name like "*.shn", the shell expands that "glob" into a list of files, passing each file name as a separate argument to the child process.

The second is redirection - the ">". That's part of the shell command - it's not passed as an argument to the command-line tool at all.

There are two ways you could address this. The first is fairly complex: You could get a list of file names manually, adding each one to the arguments array. Then you create an NSFileHandle object, and pass that to -setStandardOutput: to redirect the output from your NSTask to a file.

The other alternative is to launch /bin/sh as your task, and pass it two arguments: "-c" as the first, and the entire command you want to execute (globs and redirects included) as the second.

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSTask not using arguments?
      • From: James McConnell <email@hidden>
    • Re: NSTask not using arguments?
      • From: Andy Armstrong <email@hidden>
References: 
 >NSTask not using arguments? (From: <email@hidden>)

  • Prev by Date: Re: affine transformation of bitmap images
  • Next by Date: Re: scrollRangeToVisible is slowing me down
  • Previous by thread: Re: NSTask not using arguments?
  • Next by thread: Re: NSTask not using arguments?
  • Index(es):
    • Date
    • Thread