Hi Terry,

> > You need to join your mp3_files list onto the end of your hard-coded
> > ['mpg321'...] one so Popen() sees just one long list.
>
> And that's exactly what I've been trying to do all along :-)  (With no
> success so far.)
>
> So the latest iteration of the code creates a Python list called
> mp3_list using your glob.glob example.

Good.

> I then use a bit of string concatenation in a loop to create a string
> called mp3_files.

But you don't want a string, you want a list, as we both agree.  And
you've got one.  :-)

> This contains:
...
> eg, a list of file references separated by spaces.

The shell does many things, including globbing, and splitting the line
you give it into words for passing to the command as a list.  A list of
strings.  Not a single long string.

> If I put it into my subrocess call as:
>
>     mp3_player = subprocess.Popen(['mpg321', mp3_files])
>
> it raises no complaint, but nothing plays.

I would expect mpg321 to complain on stderr that file `./foo ./bar
./xyzzy' can't be found, i.e. there's no directory called `foo .'.  But
you're probably discarding stderr in your tests.  (Can't you leave
stdout and stderr be their default None so mpg321's output goes to the
same place as your scripts?  You're using its -q option to quieten it.)

Popen() is just kicking off the process and returning an object to
handle it.  You need to reap the child's exit value to see there's a
problem, e.g. with `ls /missing' the ls command prints its error to
stderr straight away, and then I can see it exit(3)'d with status 2,
"serious trouble" says ls(1).

    >>> p = subprocess.Popen(['ls', '/missing'])
    >>> ls: cannot access '/missing': No such file or directory

    >>> p
    <subprocess.Popen object at 0x7f5b302e6250>
    >>> p.wait()
    2
    >>>

> I've also tried os.path.join() with no success to create the list of
> files and the only method that produced something that would play in
> the shell was simple string concatenation.

In the shell you do

    mpg321 -q -m foo.mp3

In your Python you're already doing

    ['mpg321', '-q', '-m', 'foo.mp3']

to pass a list of already-separated words.  It doesn't follow that

    mpg321 -q -m foo.mp3 bar.mp3

should become

    ['mpg321', '-q', '-m', 'foo.mp3 bar.mp3']

You need to join your mp3_files list onto the end of your
fixed-arguments list so Popen() gets the one long list of
already-separated it needs.

Cheers, Ralph.

-- 
Next meeting:  Bournemouth, Tuesday, 2017-03-07 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:[email protected] / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue     / TO THE LIST OR THE AUTHOR

Reply via email to