1

I am trying to store the arguments of a command in a string instead of calling the function directly with the parameters but it seems that Powershell is not handling the string properly

ffmpeg -v quiet -stats ...  # works

$var = "-v quiet -stats"

ffmpeg $var ... #does not work

I get:

Unrecognized option 'v quiet'. Error splitting the argument list: Option not found

What is the correct way to handle this?

Thanks

mklement0
  • 382,024
  • 64
  • 607
  • 775
user206904
  • 504
  • 4
  • 16
  • 2
    try it like this: `$var = "-v", "quiet", "-stats"; ffmpeg @var` – Santiago Squarzon Dec 02 '22 at 18:25
  • 2
    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 Dec 02 '22 at 18:27
  • 1
    thanks for the hint and for linking to a similar question. Indeed, given the title of the other question, there was no way to find it unless linked to by someone who knew it already – user206904 Dec 02 '22 at 19:13
  • Good point, @user206904 - I've added more tags to your question and also to the linked duplicate, and I've amended the latter's title. – mklement0 Dec 02 '22 at 21:11

0 Answers0