0

I am writing a script in python which can connect to karaf console like sudo ./client and after logging I want to see what and all bundles are active by using commands like list| grep -i active.I want 1 single script for that.

So these two commands I want to use in my script.

Piku
  • 31
  • 7
  • 1
    Can you provide two things for us: first, show us the exact commands you'd run from a command line that you want to run in Python; second, some example output from those commands. – erapert Aug 24 '15 at 17:02
  • @erapert the command i want to run is list | grep -i active. but before that i eed to connect to my karaf console – Piku Aug 25 '15 at 06:14
  • Then the answer I gave should work. If so then please accept it. – erapert Aug 25 '15 at 19:19

1 Answers1

0

So you need:

  1. run a command and get its output
  2. parse the output and look for things

Check out the Python docs here for how to do this.

It should be something like this (I'm not at all familiar with Karaf...):

# output=`list | grep -i active`

p1 = Popen(["list"], stdout=PIPE)
# notice "stdin=p1.stdout"
p2 = Popen(["grep", "-i active"], stdin=p1.stdout, stdout=PIPE)
# Allow p1 to receive a SIGPIPE if p2 exits.
p1.stdout.close()
output = p2.communicate()[0]
erapert
  • 1,383
  • 11
  • 15