python中的子进程调用
我需要在终端中为多个文件执行以下命令SetFile -c "" -t ""
所以我创建了一个 python 脚本,它将文件名作为参数并使用调用函数来执行命令.但我不知道如何将这些 "" 标记放在调用管道中.这是代码
I need to execute the following command in terminal for multiple files
SetFile -c "" -t "" <FileName>
so I created a python script that would take filenames as arguments and use call function to execute the command. But I don't know how to put those "" marks in call pipe.
here is the code
from subprocess import call
import sys # for sys.argv
def main():
l = len(sys.argv)
l = l - 1
if(l>0):
for i in range(l):
termExecute(sys.argv[i])
def termExecute(argument):
call(["SetFile", "-c ","","-t ","","argument"])
if __name__ == '__main__':
main()
我很确定 call(["SetFile", "-c ","","-t ","","argument"])
是错误的我希望知道正确的写作方式.
I am pretty sure the call(["SetFile", "-c ","","-t ","","argument"])
is wrong I hope to know the right way of writing it.
Akuls-MacBook-Pro:~ akulsanthosh$ python3 /Users/akulsanthosh/Documents/Simple/Setfile.py /Volumes/akul/Stuff/1.jpg /Volumes/akul/Stuff/2.jpg /Volumes/akul/Stuff/3.jpg
Invalid type or creator value: '""'
Invalid type or creator value: '""'
ERROR: File Not Found. (-43) on file: argument
Invalid type or creator value: '""'
Invalid type or creator value: '""'
ERROR: File Not Found. (-43) on file: argument
Invalid type or creator value: '""'
Invalid type or creator value: '""'
ERROR: File Not Found. (-43) on file: argument
call(["SetFile", "-c ",'""',"-t ",'""',"argument"])
Python 处理 '
&"
作为有效的字符串分隔符,因此这是可能的.否则你可以转义引号.事实上,你已经使用带有 '
的字符串与 '__main__' 分隔
在您的代码中.
Python treats both '
& "
as valid string delimiters, thus this is possible. Even otherwise you can escape the quotes. In fact you've used string with '
delimits with '__main__'
in your code.
查看您收到的错误后,我会尝试以下call(["SetFile", "argument"])
After looking at the errors you're getting I would try the belowcall(["SetFile", "argument"])