You are not logged in.

#1 2012-09-12 08:02:01

Pranavg1890
Member
From: Nagpur,India
Registered: 2012-09-07
Posts: 114

using subprocess in python3 to get output of a command

Hi Friends. I am writing a python3 script for audacious to check the internet for album cover of the current playing song and then display it in conky. I am trying to call a command from python and get it's output:

audtool current-song-tuple-data album

but when i use this command in python like this:

subprocess.check_output(["audtool", "current-song-tuple-data album"])

i get the following error:

Unknown command "current-song-tuple-data album".  Try "audtool help".
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.2/subprocess.py", line 522, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['audtool', 'current-song-tuple-data album']' returned non-zero exit status 1

Please , python experts on this forum, help me.


Using Openbox + Tint2 + Idesk

Offline

#2 2012-09-12 08:54:53

lunar
Member
Registered: 2010-10-04
Posts: 95

Re: using subprocess in python3 to get output of a command

@Pranavg1890 Please read the error message.  You need to put each argument into a separate list item.

Offline

#3 2012-09-12 17:21:50

Pranavg1890
Member
From: Nagpur,India
Registered: 2012-09-07
Posts: 114

Re: using subprocess in python3 to get output of a command

@lunar can you please elaborate your point by showing me how should i write?  Many Thanks for reply.


Using Openbox + Tint2 + Idesk

Offline

#4 2012-09-13 03:32:01

Nisstyre56
Member
From: Canada
Registered: 2010-03-25
Posts: 85

Re: using subprocess in python3 to get output of a command

subprocess.check_output(["audtool", "current-song-tuple-data", "album"])

In Zen they say: If something is boring after two minutes, try it for four. If still boring, try it for eight, sixteen, thirty-two, and so on. Eventually one discovers that it's not boring at all but very interesting.
~ John Cage

Offline

#5 2012-09-13 04:14:11

Pranavg1890
Member
From: Nagpur,India
Registered: 2012-09-07
Posts: 114

Re: using subprocess in python3 to get output of a command

@Nisstyre56   Many Thanks . It Worked.


Using Openbox + Tint2 + Idesk

Offline

#6 2012-09-17 07:12:43

Darksoul71
Member
Registered: 2010-04-12
Posts: 319

Re: using subprocess in python3 to get output of a command

@Pranavg1890: Please add solved to your thread title then.
BTW: I found pexpect a good option for interacting with shell commands:
http://sourceforge.net/projects/pexpect/

It provides an easy way to deal with console output and react on certain patterns.


My archlinux x86_64 host:
AMD E350 (2x1.6GHz) / 8GB DDR3 RAM / GeForce 9500GT (passive) / Arch running from 16GB USB Stick

Offline

Board footer

Powered by FluxBB