Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8978165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:32:38+00:00 2026-06-15T19:32:38+00:00

I just want to build a little python music client on my raspberry pi.

  • 0

I just want to build a little python music client on my raspberry pi. I installed “mpg321” and it works great but now my problem. After sending the command

os.system("mpg321 -R testPlayer")

python waits for user input like play, pause or quit. If I write this in my terminal the player pause the music oder quits. Perfect but I want python to do that so I send the command

os.system("LOAD test.mp3")

where LOAD is the command for loading this mp3. But nothing happens. When I quit the player via terminal I get the error:

sh: 1: LOAD: not found

I think this means that

os.system("mpg321 -R testPlayer")

takes the whole process and after I quit it python tries to execute the comman LOAD. So how do I get these things work together?

My code:

import os

class PyMusic:
    def __init__(self):
        print "initial stuff later"

    def playFile(self, fileName, directory = ""):
        os.system("mpg321 -R testPlayer")
        os.system("LOAD test.mp3")


if __name__ == "__main__":
    pymusic = PyMusic()
    pymusic.playFile("test.mp3")

Thanks for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:32:40+00:00Added an answer on June 15, 2026 at 7:32 pm

    First, you should almost never be using os.system. See the subprocess module.

    One major advantage of using subprocess is that you can choose whatever behavior you want—run it in the background, start it and wait for it to finish (and throw an exception if it returns non-zero), interact with its stdin and stdout explicitly, whatever makes sense.

    Here, you’re not trying to run another command "LOAD test.mp3", you’re trying to pass that as input to the existing process. So:

    p = subprocess.Popen(['mpg321', '-R', 'testPlayer'], stdin=PIPE)
    

    Then you can do this:

    p.stdin.write('LOAD test.mp3\n')
    

    This is roughly equivalent to doing this from the shell:

    echo -e 'LOAD test.mp3\n' | mpg321 -R testPlayer
    

    However, you should probably read about communicate, because whenever it’s possible to figure out how to make your code work with communicate, it’s a lot simpler than trying to deal with generic I/O (especially if you’ve never coded with pipes, sockets, etc. before).

    Or, if you’re trying to interact with a command-line UI (e.g., you can’t send the command until you get the right prompt), you may want to look at an “expect” library. There are a few of these to choose from, so you should search at PyPI to find the right one for you (although I can say that I’ve used pexpect successfully in the past, and the documentation is full of samples that get the ideas across a lot more quickly than most expect documentation does).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sometimes I want to build Python or GCC from scratch just for fun, but
I want to build a navigation screen, just like installation shields has (next/previous stuff),
Just want to ask if i can use Custom Validator in client side without
Just want to ask can netbean IDE get connected to clearcase remote client server
I am trying to get to grips with OOP, and just want a little
I am about to build a little server in here and want to create
I used to build my projects with maven. Now I want to do it
I want to build a shop in which the products have a little wizard
i just join phonegap, i want a built test application. i write some code
Just want to make sure one thing. In a windows machine (either a desktop

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.