How to call linux bash from micropython
How to call linux bash from micropython
Hello,every one! I want to using efax software,How to call efax command line from micropython.Thank you very much!
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: How to call linux bash from micropython
Code: Select all
>>> import uos
>>> uos.system('ls -l')
total 40
-rw-r--r-- 1 adminpete adminpete 1006 Feb 20 2016 ffilib.py
drwxr-xr-x 2 adminpete adminpete 4096 Aug 7 2015 json
-rw-r--r-- 1 adminpete adminpete 196 Jul 29 11:27 pickle.py
drwxr-xr-x 2 adminpete adminpete 4096 Oct 13 07:18 __pycache__
-rw-r--r-- 1 adminpete adminpete 76 Oct 24 07:12 rats1.py
-rw-r--r-- 1 adminpete adminpete 95 Oct 24 07:14 rats2.py
-rw-r--r-- 1 adminpete adminpete 67 Oct 24 07:16 rats.py
-rw-r--r-- 1 adminpete adminpete 4886 Aug 7 2015 re.py
lrwxrwxrwx 1 adminpete adminpete 65 May 15 2016 upython -> /mnt/qnap2/data/Projects/MicroPython/micropython/unix/micropython
0
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: How to call linux bash from micropython
Thanks pythoncoder support.I will be try and check it out!
Re: How to call linux bash from micropython
Hello pythoncoder,
when I run the uos.system function,the error logs as follow:
>>> import os
>>> import uos
>>> uos.system()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'system'
How to solve this issue,Thanks!
when I run the uos.system function,the error logs as follow:
>>> import os
>>> import uos
>>> uos.system()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'system'
How to solve this issue,Thanks!
Re: How to call linux bash from micropython
The module is called "uos". You need to pass the command you're trying to call to the system() function.
Are you, perhaps, trying to run this on pyboard?
Code: Select all
>>> import uos
>>> uos.system('uname -a')
Linux arch 4.7.6-1-ARCH #1 SMP PREEMPT Fri Sep 30 19:28:42 CEST 2016 x86_64 GNU/Linux
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: How to call linux bash from micropython
@platforma Good point. I did assume that the original post referred to the Unix build owing to the reference to Bash
@skylin008 If you're running MicroPython on a Pyboard, ESP8266 or other hardware, you can't access a Bash prompt because these boards don't run Linux. They run MicroPython directly on the microprocessor; there is no operating system and no Bash shell. It will produce the error message you're seeing.
@skylin008 If you're running MicroPython on a Pyboard, ESP8266 or other hardware, you can't access a Bash prompt because these boards don't run Linux. They run MicroPython directly on the microprocessor; there is no operating system and no Bash shell. It will produce the error message you're seeing.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: How to call linux bash from micropython
I guess what he wanted to do is to call a bash script on the host pc triggered by an event within e.g. a pyboard.
Easiest to to that would be to write a small python script for the host machine, which communicates via the virtual serial port with the pyboard. As soon as the pyboard sends a command, the script will execute the commands like shown in Peters example.
Easiest to to that would be to write a small python script for the host machine, which communicates via the virtual serial port with the pyboard. As soon as the pyboard sends a command, the script will execute the commands like shown in Peters example.