user8183713
user8183713

Reputation:

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

Upvotes: 1

Views: 1875

Answers (1)

Jon Deaton
Jon Deaton

Reputation: 4369

Your problem is with

set VAR1=$(pwd)

You should use

VAR1=$(pwd)

instead.

Upvotes: 3

Related Questions