简体   繁体   中英

In Github, can I run a python script from a different repo than where it's stored?

Let's say I have aa repo that has a python script stored in it, then another repo where I want to run that script, such as below within repo1.

sh "python repo2/src/python.py --arg value --arg2 value2"

I'm sorry. I know this seems like a simple question, but I either don't know how to phrase my question or else it's just not possible.

Thank you.

More info: The script is part of a repo and this is where it needs to live, especially to stay modular. The other repo is a for a pipeline and it has a groovy Jenkinsfile. This is where I want to pull that script and run in within the Jenkinsfile

You can write a bash script that moves into the desired directory for you and executes the file from there. Let's say you want to execute program2.py in another directory from where you actually want to call it, then you could write a simple bash script to do this for you:

#!/bin/sh
cd path/to/dir/where/program2.py/is/stored
python program2.py --arg value

Save this bash script with a .sh file ending. Then just make it executable with chmod +x and make sure it's in the same directory as the directory where you want to execute it, of course, and you should be good to go!

假设您有一个正在读取文本文件的python脚本,您可以按照以下代码执行代码,它将起作用

python /dir/to/your/file.py /dir/to/another_file.txt 

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