Re: NSTask: Arguments with Ticks
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