• 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: Arguments with Ticks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTask: Arguments with Ticks


  • Subject: Re: NSTask: Arguments with Ticks
  • From: Sherm Pendley <email@hidden>
  • Date: Tue, 13 Feb 2007 13:51:58 -0500

On Feb 13, 2007, at 1:38 PM, Leif Singer wrote:

Hello list,

I'm trying to use NSTask to execute several command line utilities, stacked up behind each other through NSPipes. Basically, I'm trying to put together this:

netstat -ibn -I en1 | grep -m 1 en1 | awk {'print $7'}

This works fine until I need to use the ticks (') for awk. This problem isn't specific to awk, but also happens when using ticks in other utilities. E.g., netstat -ibn -I 'en1' from the cli works just as fine as without the ticks, but using NSTask this stops working. awk returns a syntax error, grep and netstat return no results.

The ticks are actually part of the shell command syntax, not part of the the argument. They're needed when you execute the above command at a shell prompt, because without them the shell would interpret $7 as a shell variable. The shell removes them and passes {print $7} as the actual argument to awk.


You're not passing arguments through a shell command interpreter when you use NSTask, so you don't need the ticks at all, escaped or otherwise. Just pass {print $7}.

sherm--

Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NSTask: Arguments with Ticks (From: Leif Singer <email@hidden>)

  • Prev by Date: NSTask: Arguments with Ticks
  • Next by Date: Re: How to set scheduling in NSThread based application
  • Previous by thread: NSTask: Arguments with Ticks
  • Next by thread: NSObjectController and Core Data
  • Index(es):
    • Date
    • Thread