Op 19 mei 2010, om 03:37 heeft Greg Guerin het volgende geschreven: > appledev wrote: > >> arguments = [NSArray arrayWithObjects: @"-c", @"/bin/df -k| /usr/bin/grep >> /dev/ | /usr/bin/awk '{print $1 $4 $5 $6;}'",nil]; > > > Your awk syntax is somewhere between quirky and wrong. Since you didn't > mention what the problem was, I will assume the output you want is not the > output you're getting.
It was just a sample to avoid the tabs \t > > I will also assume that you ARE getting some output, despite Alastair > Houghton previously noted comment that waiting for termination before reading > stdout can be unsafe. Unless you have a whole lot of mounted disks, the pipe > buffer won't fill up and cause deadlock (it's about 16 KB, empirically > determined, in all Mac OS X versions I've tested, since 10.0). I know it is very small just a few hundred bytes, but it is still good to know. > If you want the default output field separator, you need this awk line: > print $1, $4, $5, $6 > > The default output field separator is defined by the awk variable named OFS. > To use tab as OFS: > { OFS="\t"; print $1, $4, $5, $6;} > > You can discover all this simply by reading awk's man page. > simply?? Now you ask to much. ;-) In fact I did read the page, but just overlooked that OutputFieldSep. Mainly because my script did work in the terminal and was focused on where is my output. > > The resulting bash command-line is: > /bin/df -k| /usr/bin/grep /dev/ | \ > /usr/bin/awk '{ OFS="\t"; print $1, $4, $5, $6;}' > > I have inserted a \ to force a continuation line, so mail doesn't line-fold > badly. > > To encode that properly as an Objective-C string literal, you need to escape > both the double-quotes and the backslash: > arguments = [NSArray arrayWithObjects: > @"-c", > @"/bin/df -k| /usr/bin/grep /dev/ | /usr/bin/awk '{ OFS=\"\\t\"; print $1, > $4, $5, $6;}'", > nil]; Yes I got that and will save it, thanks. Btw, yes I believe that awk can filter /dev/, but this was the shortest that I could come with. > > (The Objective-C was written in mail and not compiled. The command-line with > the modified awk code was tested in bash.) > > And I should note that awk is perfectly capable of matching the "/dev/" > pattern by itself with no assistance from grep. This is left as an exercise > for the interested reader. Because I didn't see any result, I noticed that this happened only when I use /bin/sh -c. My code was just a short piece in main as test bed, and did trust my NSLog output which was ok and visible in the xcode console when NOT using /bin/sh. Because yesterday it was an early and long day, I did figure out this morning that when using /bin/sh NSLog is redirected to the system console and not visible in xcode console anymore. Now my code is alive and kicking, how can I get NSLog back into the Xcode console, because all my later NSLogs are not visible in xcode. How do I reset the stnd output? Should I, somewhere, call or send exit? _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com