Monday, October 24, 2016

Python script to run the bash script file

we can run the  script file or executable file from the progamming just simply by ./script_file name . Sometimes we may reach in to the situation that we need to run through the python program. so inorder to run the script from python file can be easily done through  subprocess  of python.

The scenario of this program is at a certain location, I have several folder  like A,B,C, D and so on and each folder has the executable files. I need to run each of them. And to do so I can go to each folder and run the executable, however this is tedious. thus This is the program which runs the executable files from the each folder.


import os
import subprocess
rootdir = '/home/laxmi/Desktop/assembler/assignment_grad/assign3/grade'

for subdir, dirs, files in os.walk(rootdir):
    for file in dirs:
        path = os.path.join(subdir, file)
        # print file
        # abspath = os.path.abspath(__file__)
        # print abspath
        # dname = os.path.dirname(abspath)
        # print dname
        os.chdir(path)
        print " --------entering folder------"
        print "%s"%path
        subprocess.call('./asm64 *.asm',shell=True)

No comments:

Post a Comment