TIMEX
TIMEX

Reputation: 272374

Inside python code, how do I run a .sh script?

Will it continue the code after it's run? Or will it stop at that line until the script is done?

Upvotes: 5

Views: 36226

Answers (3)

Senthil Kumaran
Senthil Kumaran

Reputation: 56951

You can use os.system or subprocess.Popen or subprocess.call but when using subprocess methods make sure you use shell=True. And executing it via system call in all these methods is blocking. The python script will complete and then go the next step.

Upvotes: 1

Frost.baka
Frost.baka

Reputation: 8031

import os
os.system('./script.sh')

python script won't stop until sh is finished

Upvotes: 8

ThiefMaster
ThiefMaster

Reputation: 318778

Using subprocess.call is the easiest way. It will not return until the executed program has terminated. Have a look at the other methods of the subprocess module if you need different behaviour.

Upvotes: 10

Related Questions