Python Forum
Values into system calls (RPi 4 Raspbian Buster Thonny)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Values into system calls (RPi 4 Raspbian Buster Thonny)
#2
you need to construct the command string with the values of b0, b1 and b2

>>> b0 = hex(12*12)[2:4]
>>> b1 = hex(5*12)[2:4]
>>> b2 = hex(100+27)[2:4]
>>> cmd = ' '.join(["amidi -p hw:1,0 -S", b0, b1, b2])
>>> cmd
'amidi -p hw:1,0 -S 90 3c 7f'
>>> cmd = f"amidi -p hw:1,0 -S {b0} {b1} {b2}"
>>> cmd
'amidi -p hw:1,0 -S 90 3c 7f'
>>> b0 = 0x90
>>> b1 = 0x3c
>>> b2 = 0x7f
>>> cmd = f"amidi -p hw:1,0 -S {b0:x} {b1:x} {b2:x}"
>>> cmd
'amidi -p hw:1,0 -S 90 3c 7f'
>>>
also note you don't need to convert the result from hex() to str, it's already str.
by the way it's better to use subprocess module, e.g. subprocess.run(), as mentioned in the docs for os.system():

Quote:The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function. See the Replacing Older Functions with the subprocess Module section in the subprocess documentation for some helpful recipes.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Values into system calls (RPi 4 Raspbian Buster Thonny) - by buran - Aug-27-2019, 07:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Sonar Code in Thonny for Pi Pico iansmiler 1 423 Nov-22-2023, 12:27 PM
Last Post: deanhystad
  Calls to Attributes of a Class SKarimi 3 3,525 Apr-22-2021, 04:18 PM
Last Post: SKarimi
  Difference between os.system("clear") and os.system("cls") chmsrohit 7 16,859 Jan-11-2021, 06:30 PM
Last Post: ykumar34
  Minimal python install for thonny ide DanielRossinsky 0 1,555 Jun-11-2020, 02:31 PM
Last Post: DanielRossinsky
  Does "import xlrd" work in Thonny? cnutakor 3 3,094 Apr-30-2020, 12:41 AM
Last Post: Larz60+
Question Difference between Python's os.system and Perl's system command Agile741 13 7,092 Dec-02-2019, 04:41 PM
Last Post: Agile741
  Need help with a function that calls other functions. skurrtboi 4 2,636 Sep-30-2019, 09:28 PM
Last Post: stullis
  Deluge (Python 2.7) on Raspbian with YARSS2 - certificate_transparency error Matt872000 0 1,579 Apr-21-2019, 02:39 AM
Last Post: Matt872000
  Testing function calls jenselme 1 2,742 Jul-25-2018, 10:33 AM
Last Post: Larz60+
  function state between calls Skaperen 5 5,251 Feb-08-2018, 02:20 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020