简体   繁体   中英

how to pass directory as arguments to python script using shell command?

I am trying to pass two directories to my python script which just prints out the directory. But somehow its not working. Below is the code

shellscript.sh:

set VAR1=$(pwd)
echo $VAR1
set VAR2=$(pwd)
echo VAR2
python.exe mypython_script.py "$VAR1" "$VAR2"

mypython_script.py:

import os
import sys

if __name__ = '__main__':
    print(sys.argv[1])
    print(sys.argv[2])

The echo is printing the path, but the terminal also does print the script call line. There its showing python.exe mypython_script.py '' '' and then print statements are printing empty string. Could anyone point out to me where the problem is? Thank you

Your problem is with

set VAR1=$(pwd)

You should use

VAR1=$(pwd)

instead.

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