Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use the path as an argument in shell file from python

Tags:

python

shell

I want to call from python a shell script which contain the running of another python function. I would like to use for that subprocess method. My code so far look like:

arguments = ["./my_shell.sh", path]
ret_val = subprocess.Popen(arguments, stdout=subprocess.PIPE)

while the script is the following:

#!/bin/sh

cd ... 
python -c "from file import method; 
method()"

How can I give in the directory (to cd) of the path that I pass as an argument in the shell file?

like image 720
Jose Ramon Avatar asked Apr 24 '26 21:04

Jose Ramon


1 Answers

You can access your arguments as $1, $2, etc. So your cd command would simply be cd $1.

like image 147
busybear Avatar answered Apr 26 '26 09:04

busybear



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!