10

I've got a series of commands I'm making from the command line where I call certain utilities. Specifically:

root@beaglebone:~# canconfig can0 bitrate 50000 ctrlmode triple-sampling on loopback onroot@beaglebone:~# cansend can0 -i 0x10 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88root@beaglebone:~# cansequence can0 -p

I can't seem to figure out (or find clear documentation on) how exactly I write a Python script to send these commands. I haven't used theos module before, but suspect maybe that's where I should be looking?

Peter Mortensen's user avatar
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
askedFeb 19, 2013 at 14:09
Chris's user avatar
0

2 Answers2

3

With subprocess one can conveniently perform command-line commands and retrieve the output or whether an error occurred:

import subprocessdef external_command(cmd):     process = subprocess.Popen(cmd.split(' '),                           stdout=subprocess.PIPE,                            stderr=subprocess.PIPE)    # wait for the process to terminate    out, err = process.communicate()    errcode = process.returncode    return errcode, out, err

Example:

print external_command('ls -l')

It should be no problem to rearrange the return values.

answeredFeb 19, 2013 at 14:13
Alex's user avatar
Sign up to request clarification or add additional context in comments.

Comments

1

Usesubprocess.

Example:

>>> subprocess.call(["ls", "-l"])0>>> subprocess.call("exit 1", shell=True)1
Peter Mortensen's user avatar
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answeredFeb 19, 2013 at 14:13
Fredrik Pihl's user avatar

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.