import subprocess # Read the File containing list of commands fhr = open("sample_file",'r') # SHELL FOR EXECUTING BUILD COMMANDS SHELL_CMD = "cmd.exe" shellproc = subprocess.Popen(SHELL_CMD,shell=True,stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) expected = '<$$$>\r\n' prompt_cmd = 'prompt $L$$$$$$$G$_' shellproc.stdin.write('%s\n' % prompt_cmd) # Read the file line by line for line in fhr: ## ## SET of Statements to replace all the tokens cmd = <## processed line##> shellproc.stdin.write('%s\n' % cmd) while True: output = shellproc.stdout.readline() if output.endswith(expected): break logger.info(output) print "Waiting for subshell to terminate" shellproc.stdin.write("exit\n") shellproc.wait() print "Successfully Executed all the Commands [Done]"