How to call a shell script function/variable from python?

前端 未结 6 1139
庸人自扰
庸人自扰 2021-01-19 01:56

Is there any way to call a shell script and use the functions/variable defined in the script from python?

The script is unix_shell.sh

#!/bin/bash
fun         


        
6条回答
  •  粉色の甜心
    2021-01-19 02:24

    With the help of above answer and this answer, I come up with this:

    import subprocess
    command = 'bash -c "source ~/.fileContainingTheFunction && theFunction"'
    stdout = subprocess.getoutput(command)
    print(stdout)
    

    I'm using Python 3.6.5 in Ubuntu 18.04 LTS.

提交回复
热议问题