1

I have roughly the following script:

# Those are actually passed as cmdlet parameters into the script
$FFmpegPath = "ffmpeg"
$Args = "-i MyInput.mp4 MyOutput.webm"

& $FFmpegPath $Args

The ShellExecute that I expect this to perform is ffmpeg -i MyInput.mp4 MyOutput.webm. FFmpeg, however, complains that it can't properly parse the arguments, and upon further inspection using Process Hacker, it turns out that the actual command line that PowerShell is executing is ffmpeg "-i MyInput.mp4 MyOutput.webm".

How do I get rid of those quotation marks and pass the whole string as one or more individual arguments with the usual argument separator syntax (spaces separate arguments, internal escaped quotations stay as quotes and prevent spaces from becoming delimiters, etc)?

Kotauskas
  • 1,239
  • 11
  • 31
  • 3
    You'll need to pass the args as an array, for example: `$args = @("option", "path1", "path2")` – nimizen Aug 09 '22 at 11:56
  • In short: In order to programmatically pass arguments to external programs, construct an _array_, with each parameter (option) name and parameter value / positional argument (operand) becoming its own element. E.g., to execute `foo -o "bar baz"`, use `$a = '-o', 'bar baz'; foo $a`. See the linked duplicate for details. – mklement0 Aug 09 '22 at 12:58

0 Answers0