我有个python脚本,其中一个接收参数是列表,由于的列表过长,导致我在windows执行时,因为windows的限制,总是报错 “[WinError 206] 文件名或扩展名太长。”
# 使用流传递
# a.py
cmd = ["python.exe",
"D:.\computing_package\xxx.py",
"--data",
"-",
"--parameter1",
"30"]
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
a = bytes(str(超长list), "utf-8")
stdout, stderr = proc.communicate(input=a)
# b.py 子进程
if __name__ == "__main__":
# Set up command line argument parser
parser = argparse.ArgumentParser(description="xxxxxxx")
parser.add_argument("--data", type=str, help="Data in the format '[[x1, y1], [x2, y2], ...]'")
parser.add_argument("--parameter1", type=str, default=0.5, help="parameter")
args = parser.parse_args()
# 流传递
if args.data == '-':
data = json.loads(sys.stdin.read())
# 正常传递
else:
data = ast.literal_eval(args.data)