Results 1 to 3 of 3

Thread: save terminal responce to string in python

  1. #1
    Join Date
    Nov 2011
    Beans
    14

    Post save terminal responce to string in python

    im not sure if this is supposed to be simple or really complicated or if its possible (really hope so),
    but i want to be able to send out a command to the terminal from python which i can do like so.

    import os

    os.system("clear")
    os.system("amixer get Master")

    when running this in terminal the terminal come's up with this.

    Simple mixer control 'Master',0
    Capabilities: pvolume pvolume-joined pswitch pswitch-joined penum
    Playback channels: Mono
    Limits: Playback 0 - 87
    Mono: Playback 42 [48%] [-33.75dB] [on]
    jordiston@JordistonUbuntu:~$

    In bash I can easily save this to a string, but is their anyway for python?

  2. #2
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: save terminal responce to string in python

    Code:
    import subprocess
    
    output = subprocess.check_output("amixer get Master", shell=True)
    print(output)

  3. #3
    Join Date
    Nov 2011
    Beans
    14

    Re: save terminal responce to string in python

    THANK YOU!! Worked perfectly.
    I'm using it to make an indicator for alsa sound volume. I deleted pulseaudio and theirs no indicator for people that only use alsa.

    It's working good now. I am still wondering though if theirs any drawback on using this method. like if its slower or bad in anyway and if their'd be a better way to do this Or if its good like this.

    It doesn't take a percent off of my cpu and i have a timer that controls how fast it checks.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •