I'm executing a set of commands that first require me to call bash. I am trying to automate these commands by writing a Python script to do this. My first command obviously needs to be bash, so I run
p = subprocess.call(['bash'])
and it launches the bash shell no problem.
Where I then have problems is trying to execute the remaining code in the bash environment. I thought perhaps there was a need for process communication (i.e. redirecting stdout as in
p0 = subprocess.Popen(cmd, stdout=subprocess.PIPE)
p1 = subprocess.Popen(['bash'], stdin=p0.stdout)
p1.communicate()
) but the piping doesn't seem to solve my problem.
How can I write this script so that it mimics the following sequential Linux commands?
$ bash
$ cmd1
$ cmd2
...
I'm working with Ubuntu 14.04 and Python 2.7.6.
Thanks in advance for the guidance!
bashand then executecmd1. Then open another terminal, executebashand then executecmd2, and so on. In other words, each command runs a process that must be running in bash when I launch the subsequent processbashonly matters if your normal shell isn't alreadybashI would imagine. In which case you probably just want tosubprocess.call(orcall_checkor whatever the safer version of that function is) the commandbash -c cmd(or justcmdif the manualbashisn't actually necessary).