-1

I've two batch files, A.bat and B.bat, as well as a python script C.py
A.bat looks something like this:

call B.bat hello

Now of course, if I use %1 in B.bat, the batch file will view that value as "hello". Now, if I have B.bat call C.py, I need C.py to be able to recognize that %1 is hello, the same way B.bat recognizes that.
Of course, I've tried simply writing in B.bat:

call C.py %1

And then using %1 in C.py like I would in any batch file, but this did not work. I don't know if this means that I can't use %1 itself as a parameter or if I can't use a parameter of this type in python, or both. So, how would I be able to use a parameter in C.py that was defined in A.bat?

Koloktos
  • 123
  • 7

1 Answers1

2

To access parameters in Python, use:

import sys
print(sys.argv[1])  # view the first parameter, similar to %1 in .bat

Ref: https://docs.python.org/3/library/sys.html#sys.argv

Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251