Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
调用批处理文件,该批处理文件调用使用初始批处理文件中定义的参数的python脚本_Python_Python 3.x_Batch File - Fatal编程技术网

调用批处理文件,该批处理文件调用使用初始批处理文件中定义的参数的python脚本

调用批处理文件,该批处理文件调用使用初始批处理文件中定义的参数的python脚本,python,python-3.x,batch-file,Python,Python 3.x,Batch File,我有两个批处理文件,A.bat和B.bat,还有一个python脚本C.py 蝙蝠看起来像这样: call B.bat hello 当然,如果我在B.bat中使用%1,批处理文件会将该值视为“hello”。现在,如果我让B.bat调用C.py,我需要C.py能够识别%1是hello,就像B.bat识别那样。 当然,我试着简单地用B.bat写: call C.py %1 然后像在任何批处理文件中一样在C.py中使用%1,但这不起作用。我不知道这是否意味着我不能使用%1本身作为参数,或者我不能在

我有两个批处理文件,A.bat和B.bat,还有一个python脚本C.py
蝙蝠看起来像这样:

call B.bat hello
当然,如果我在B.bat中使用%1,批处理文件会将该值视为“hello”。现在,如果我让B.bat调用C.py,我需要C.py能够识别%1是hello,就像B.bat识别那样。
当然,我试着简单地用B.bat写:

call C.py %1

然后像在任何批处理文件中一样在C.py中使用%1,但这不起作用。我不知道这是否意味着我不能使用%1本身作为参数,或者我不能在python中使用这种类型的参数,或者两者兼而有之。那么,我如何才能在C.py中使用a.bat中定义的参数呢?

要访问Python中的参数,请使用:

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