gpt4 book ai didi

python - 在 Python subprocess.call() 中转义特殊字符 (*)

转载 作者:行者123 更新时间:2023-12-01 04:57:45 24 4
gpt4 key购买 nike

我似乎无法转义这些特殊字符 - *。我正在尝试使用带有以下行的 Python 脚本复制一些文件

subprocess.call(r"mkdir E:\CONTENT\Full1",shell=True)
subprocess.call(r"copy","E:\DATA FOR CONTENT\*.*","E:\CONTENT\Full1",shell=True)
subprocess.call(r"fsutil file createnew ","E:\CONTENT\versionfile.txt","6500000",shell=True)

但是我在第二行收到以下错误

Traceback (most recent call last):
File "basic1.py", line 9, in <module>
subprocess.call(r"copy","E:\DATA FOR CONTENT\*.*","E:\CONTENT\Full1",shell=True)
File "C:\Python34\lib\subprocess.py", line 537, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Python34\lib\subprocess.py", line 767, in __init__
raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer

此外,我讨厌使用 CSV 样式(“arg1”、“arg2”...)传递它。有什么方法可以将其作为原始字符串传递吗?

最佳答案

args should be a sequence of program arguments or else a single string.

subprocess.call(["copy", r"E:\DATA FOR CONTENT\*.*", r"E:\CONTENT\Full1"], shell=True)

关于python - 在 Python subprocess.call() 中转义特殊字符 (*),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26986506/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com