Bvs Revanth
Bvs Revanth

Reputation: 59

How to execute more than one shell command using python subprocess module?

I have more than one command that has to be executed on the shell and I want to the run all the commands on the same shell . I have the commands stored in a file(command.txt) and I want all of them to be executed in a single go using the subprocess.run() function in python

I tried something like this but this doesn't work.

subprocess.run(str(open("command.txt")),shell = True)

Upvotes: 0

Views: 78

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295278

subprocess.run(['sh', 'command.txt'])

Note that we are not using shell=True here, as we already start sh ourselves.

Upvotes: 1

Related Questions