0

I am trying to run a .sh script from python.

I saw that this can be done in various ways such as:

import subprocess

subprocess.call(["./test.sh"])

or

import os 

os.system("sh test.sh")

However this assumes that test.sh is in the same folder where you are running the script from. What if I want to run the .sh which is in a specific folder?

I tried the following but with no luck:

import subprocess

subprocess.call(["cd ~/ros_ws", "./intera.sh"])

import subprocess

subprocess.call(["cd ~/ros_ws", "./intera.sh"], shell=True)

Thanks for the help.

gapansi99
  • 187
  • 1
  • 1
  • 7
  • 1
    Does this answer your question? [Equivalent of shell 'cd' command to change the working directory?](https://stackoverflow.com/questions/431684/equivalent-of-shell-cd-command-to-change-the-working-directory) – Marc Sances Oct 26 '21 at 20:40

1 Answers1

0

The subprocess.call has an cwd function argument (change working directory)

import subprocess

subprocess.call(["./intera.sh"], cwd="~/ros_ws")