简体   繁体   中英

Creating files from a Python script within a shell script within a shell script

I'm trying to run a Python script from a shell script within a shell script, but I'm running into some problems.

Imagine my root shell script looks like this:

echo "test0"
sh ./test/test1/test2.sh

and my test2.sh:

echo "test2"
python testme.py

The python file is in the same directory as test2.sh but test2.sh's working directory seems to be the root's so it cannot find the python script. So, if I give the python script's absolute location to test2.sh , the python file runs, but when the python file creates new files, it's created in the root.

If there is a solution so that I don't have to edit the python script to create new files in the directory of the python script, please let me know.

Here is your root script:

echo "test0"
cd test/test1
sh ./test2.sh

Your script test2 is launched with the environment of your root script. So you just have to cd in your root script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM