First of all, I'm using Ubuntu 20.04 and Python 3.8. I would like to run a program that takes command line inputs. I managed to start the program from python with the os.system() command, but after starting the program it is impossible to send the inputs. The program in question is a product interface application that uses the CubeSat Space Protocol (CSP) as a language. However, the inputs used are encoded in a .c file with their corresponding .h header.
In the shell, it looks like this: starting the program
In python, it looks like this:
import os
os.chdir('/home/augustin/workspaceGS/gs-sw-nanosoft-product-interface-application-2.5.1')
os.system('./waf')
os.system('./build/csp-client -k/dev/ttyUSB1')
os.system('cmp ident') #cmp ident is typically the kind of command that does not work on python
The output is the same as in the shell but without the "cmp ident output", that is to say it's impossible for me to use the csp-client#
As you can probably see, I'm a real beginner trying to be as clear and precise as possible. I can of course try to give more information if needed. Thanks for your help !
I'll try and give you some hints to get you started - though bear in mind I do not know any of your tools, i.e.
waforcsp-client, but hopefully that will not matter.I'll number my points so you can refer to the steps easily.
Point 1
If
wafis a build system, I wouldn't keep running that every time you want to run yourcsp-client. Just usewafto rebuild when you have changed your code - that should save time.Point 2
When you change directory to
/home/augustin/workspaceGS/gs-sw-nanosoft-product-interface-application-2.5.1and then run./build/csp-clientyou are effectively running:But that is rather annoying, so I would make a symbolic link to that that from
/usr/local/binso that you can run it just with:So, I would make that symlink with:
You MAY need to put
sudoat the start of that command. Once you have that, you should be able to just run:Point 3
Your Python code doesn't work because every
os.system()starts a completely new shell, unrelated to the previous line or shell. And the shell that it starts then exits before your nextos.system()command.As a result, the
cmp identcommand never goes to thecsp-client. You really need to send thecmp identcommand on thestdinor "standard input" ofcsp-client. You can do that in Python, it is described here, but it's not all that easy for a beginner.Instead of that, if you just have aa few limited commands you need to send, such as "take a picture", I would make and test complete
bashscripts in the Terminal, till I got them right and then just call those from Python. So, I would make abashscript in your HOME directory called, saycsp-snapand put something like this in it:Now make that executable (only necessary once) with:
And then you can test it with:
If that works, you can copy the script to
/usr/local/binwith:You may need
sudoat the start again.Then you should be able to take photos from anywhere just with:
Then your Python code becomes easy: