Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running .sh file from Python script?

I am having trouble running a .sh script in Oracle Linux 6.8 using a python script I have developed. I've developed these scripts in Windows OS and they run without a problem, now I am trying to modify these scripts to run them on Linux but I am having problems since I am not familiar with Linux OS.

I run a .bat file in Windows using the Popen command in python, for example: p = Popen("StartScript.bat", cwd=r"My path")

Where StartScript.bat is the .bat file, and My Path is the path where the .bat file is located. This works very good in Windows OS, but how do I do the same for Linux OS, if I want to run a StartScript.sh file.

like image 603
viganqerimi Avatar asked Sep 18 '25 11:09

viganqerimi


2 Answers

execute a shell-script from Python subprocess

How to execute a shell script through python

Please take a look at these two threads. Hope it helps.

like image 94
Gaurav Pathak Avatar answered Sep 20 '25 00:09

Gaurav Pathak


use this lines:

import os
os.popen('sh command')

for example

import os
os.popen('sh /home/oracle/scripts/start.sh')

enjoy

like image 30
Francesco Renzi Avatar answered Sep 20 '25 01:09

Francesco Renzi