2

I've got a command line utility from canutils called candump. It works like this:

I run candump (specifying the bus from which I want to dump)

root@beaglebone: candump can0

It then runs until I end it using CTRL+C

However, when I run it in a python script like so.

Popen(["candump","can0"],stdout=PIPE)

or

call(["candump","can0"])

I'm not sure how to end it. Any ideas?

Chris
  • 9,603
  • 15
  • 46
  • 67
  • [Relevant.](http://stackoverflow.com/questions/13030162/manually-closing-subprocess-pipe) – Cairnarvon Mar 06 '13 at 22:58
  • 1
    `Popen.terminate()` and `Popen.kill()` should work if you don't want to use `send_signal`. [Docs](http://docs.python.org/2/library/subprocess.html#subprocess.Popen.terminate) – msvalkon Mar 06 '13 at 23:01

2 Answers2

3

Don't use use the call command if you want control over the subprocess

If you use Popen like you did above you should assign it to a variable like this:

p = Popen(["candump","can0"],stdout=PIPE)

Once you have p then you can use one of the following SIGNAL commands on it http://docs.python.org/2/library/subprocess.html#subprocess.Popen.send_signal

Necrolyte2
  • 738
  • 5
  • 13
2

Use Popen(), and call send_signal(signal.SIGINT) on the returned Popen object.

nneonneo
  • 171,345
  • 36
  • 312
  • 383