0

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()

I am pretty sure the call(["SetFile", "-c ","","-t ","","argument"]) is wrong I hope to know the right way of writing it.

edit:

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

2 Answers2

0

call(["SetFile", "-c ",'""',"-t ",'""',"argument"])

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.

After looking at the errors you're getting I would try the below
call(["SetFile", "argument"])

kaza
  • 2,317
  • 1
  • 16
  • 25
  • Invalid type or creator value: '""' Invalid type or creator value: '""' ERROR: File Not Found. (-43) on file: argument – akul santhosh Sep 12 '17 at 05:10
  • Can you run the command in your CMD/shell with those inputs and paste the working command here? – kaza Sep 12 '17 at 05:11
  • Add the working command (outside of python) to your question, that way it would be easier. – kaza Sep 12 '17 at 05:15
  • I meant run it with a proper Filename and paste the command and output. – kaza Sep 12 '17 at 05:18
  • As per the error shown`Invalid type or creator value:` which is different from first error. It seems SetFile is confused if you send it `""`. – kaza Sep 12 '17 at 05:21
  • I believe `-c` should be for `creator` and `-t` should be for `type` – kaza Sep 12 '17 at 05:25
  • Cool, let me know if you've any questions or mark it as answered! – kaza Sep 12 '17 at 05:33
0

According to the documentation, you can pass empty strings:

args is required for all calls and should be a string, or a sequence of program arguments. Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names). If passing a single string, either shell must be True (see below) or else the string must simply name the program to be executed without specifying any arguments.

You can also pass quotes: "''"

Laurent LAPORTE
  • 21,958
  • 6
  • 58
  • 103