execute a linux command using python

Problem Statement: A script to install packages in oracle linux 7 using python

Scenario: I have a text file "oracle_package-requirement.txt" --> contains packages name i am using the following program to append that to list type variable using following code:

!/usr/bin/env python

import os f = open("/home/dipesh/oracle_package_requirement.txt","r") myList = [] for line in f: myList.append(line)

now i want to pass myList as input to yum -y install

So my question to the community is how can write this in my python code????


您可以使用子流程模块:

import os
import subprocess

f = open("/home/dipesh/oracle_package_requirement.txt","r")
myList = []
for line in f:
  myList.append(line.strip()) # strip to get rid of trailing newline
subprocess.check_call(['yum', '-y', 'install'] + myList)
链接地址: http://www.djcxy.com/p/55082.html

上一篇: 将PostgreSQL的PL / pgSQL输出保存为CSV文件

下一篇: 使用python执行一个linux命令