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

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

    No, that's not possible. You can execute a shell script, pass parameters on the command line, and it could print data out, which you could parse from Python.

    But that's not really calling the function. That's still executing bash with options and getting a string back on stdio.

    That might do what you want. But it's probably not the right way to do it. Bash can not do that many things that Python can not. Implement the function in Python instead.

提交回复
热议问题