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

前端 未结 6 1242
庸人自扰
庸人自扰 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 01:59

    Yes, in a similar way to how you would call it from another bash script:

    import subprocess
    subprocess.check_output(['bash', '-c', 'source unix_shell.sh && foo'])
    

提交回复
热议问题