0

So, I have a bash script that feeds out data from a sensor that is connected to the NVidea Jetson TK-1 in string format in the shell. Is there any way I can run a python script that initializes the bash script. Takes the output data in bash, feeds it back into a python string variable where it can be parsed? I cannot edit the bash script.

Thanks

1 Answers1

1

In python:

   import subprocess
   bash_output = subprocess.check_output('run bash script here')

Subprocess.check_output sends commands to the shell and the shell pipes the results back to python. Look at examples of using and documentation on subprocess.check_output here.

Charlie Haley
  • 4,152
  • 4
  • 22
  • 36
  • Will this work when I can only run the bash script once and new data comes out every ~10ms? – strozster Aug 04 '15 at 20:17
  • Ah, no it will not. subprocess.check_output waits for the process to finish. Could you output from bash to a file and use python to poll for changes in the file? – Charlie Haley Aug 04 '15 at 20:20
  • I have no access to the bash script if that is what you mean – strozster Aug 04 '15 at 20:25
  • He means can you change from using the bash script to a python alternative. – MeetTitan Aug 04 '15 at 20:25
  • I mean, can you run the bash script like "bash_script_name > bash_output.txt" and then while that is running, run a python program that opens and reads the contents of that file every second or something? – Charlie Haley Aug 04 '15 at 20:28
  • No, it is not possible. The output is from a sample application that I have no way to edit. I just need the output from the sample application which is printed on the console as a string. I just thought python was the way to go. – strozster Aug 04 '15 at 20:29
  • Could you `tee` the output? Or `tail -f` perhaps and Popen with a pipe to stdout, maybe? – MeetTitan Aug 04 '15 at 20:30
  • I guess the text output could work but wouldn't it not be possible since both scripts would need to be running at the same time? – strozster Aug 04 '15 at 20:31
  • I'm not sure what you mean with 'tee' or 'tail -f' I'm not familiar with the function of those – strozster Aug 04 '15 at 20:33