[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Using terminal output as input



On Thu, 2009-05-14 at 13:26 -0400, S Scharf wrote:
> 
> On Thu, May 14, 2009 at 11:13 AM, Dotan Cohen <dotancohen@gmail.com>
> wrote:
>         > Not pretty but how about
>         > `ekiga | head -2 | tail -1`
>         >
>         > (note use of backticks)
>         >
>         
>         
>         That's creative! It doesn't seem to work on this system, I
>         will try on
>         Real Debian (tm) when I get home. However, it does require
>         foreknowledge of the output, which I suppose is all right if
>         the user
>         can run the same command again.
> 
> Oops, the output of ekiga is going to stderr and not stdout. Only
> stdout gets piped.
> 
> Anyone know how to capture and pipe stdout?

I am not sure that's something I would do... but here it is:

$`ekiga  2>&1 | sed -n 2p`

Where you tell sed:
   "-n" => Don't print the lines by default.
   "2p" => When you match the line Number 2, then _p_rint it.
(BTW, the dollar sign is the prompt, not something to type)

Alternatively, this one could be an option because your are prompted
before running the command:

$ekiga  2>&1 | xargs -n 1 -p sh -c

Obviously, it becomes much more sexy if you create an alias:
$alias Qrun='xargs -n 1 -p sh -c'
So just type:
$ekiga  2>&1 | Qrun

  sh -c The program 'ekiga' is currently not installed.  You can install
  it by typing: ?...n
  sh -c sudo apt-get install ekiga ?...y

And here you go !

Regards,

Franklin

P.S. All that is completely untested ;)


Reply to: