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

前端 未结 6 1287
庸人自扰
庸人自扰 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:02

    You could separate each function into their own bash file. Then use Python to pass the right parameters to each separate bash file.

    This may be easier than just re-writing the bash functions in Python yourself.

    You can then call these functions using

    import subprocess
    subprocess.call(['bash', 'function1.sh'])
    subprocess.call(['bash', 'function2.sh'])
    # etc. etc.
    

    You can use subprocess to pass parameters too.

提交回复
热议问题