【发布时间】:2018-04-22 07:00:55
【问题描述】:
这个问题是this question 的简单版本。
简单来说,我在~/.bash_profile 上定义了一个自定义bash 函数my_func,并在同一环境中使用了另外两个定义的bash 函数。
另外,my_func 接受两个参数,比如说a 和b。 my_func 所做的是连接到远程服务器并发送一些文件(这些文件由a 和b 确定)。
如果我在bash shell 上输入:
. my_func a b 一切正常,我在屏幕上看到了一些打印语句。
但是,如果我包括:
subprocess.call(['#!/bin/bash . my_func a b'], shell=True) 似乎什么也没发生。
我尝试通过以下方式导出my_func 使用的所有 bash 函数:
subprocess.call(['#!/bin/bash export -f my_func'], shell=True) 我对my_func 使用的其余函数做了同样的事情。
编辑:
如果我使用subprocess.call(['bash', '-c' ,'my_func a b], shell=True),bash shell 将变为bash-3.2$
【问题讨论】:
标签: python bash macos shell subprocess