0

I am trying to use file to determine what type a file is. In stderr, I keep getting a usage message in stderr "Usage...." which tells me I am doing something wrong with the arguments but not WHAT is wrong. This is my code below. For more context, from_file_path is a temporary file used to store downloaded info. Other subprocess calls work on this file, so I know there is nothing wrong with the file itself.

subprocess.run(["file", from_file_path], check=True, shell=True)
  • Btw, I know using Shell=True is generally not good, but there is no user input in this case so should be fine I think – user18530011 Sep 06 '22 at 21:06
  • Very, very short summary from the linked duplicates: `subprocess.run(['file "$0"', from_file_path], check=True, shell=True)` does what you're asking for, because the first list entry is treated as code for a shell to execute, and later ones are that shell's positional arguments starting from `$0`. – Charles Duffy Sep 06 '22 at 21:48

0 Answers0