这就是我如何运行myscript.sh中设置的bash脚本
#!/bin/bash
import subprocess
child = subprocess.Popen(['bash', '-c', '/bin/bash myscript.sh'], stdout = subprocess.PIPE)
output=child.communicate()
print(output)
myscript.sh
为什么我要这样做是因为我必须运行的bash脚本没有export命令,所以我在这里回音。代码如下。我知道echoong不会设置环境变量,但我只想回显它并获取值,以便回显而不是导出
#!/bin/bash
source ia_servers
echo $IA_SRV_cs68_64
其中,$IA\u SRV\u cs68\u 64
下面是列出变量值的ia\u servers文件 看起来像这样
IA_SRV_cs68_64="ds1 ds2 ds3 ds5 "
这就是其中的变量。因为太长,许多其他的变量被设置在它里面
从终端测试效果良好:
打印所需的值集
问题: 尽管myscript.sh正在运行并打印变量。我想要的是,我不想创建一个单独的文件,而是在python中编写bash脚本来回显myscript.sh中的变量
How do I accomplish it within the python rather rather than making the script file and run that.
这里有一种通用的方法来运行任何类型的脚本或程序,其中程序输入嵌入在Python脚本中
相关问题 更多 >
编程相关推荐