2

In my command line, I start my process like this:

ffmpeg -f dshow i video="Integrated Camera" c:\test.mp4

I want to do the same in PowerShell.

I tried:

$args = " -f dshow i video='Integrated Camera' c:\test.mp4"
Start-Process -FilePath ffmpeg.exe -ArgumentList $args

And I tried:

$args = " -f dshow i video=\"Integrated Camera\" c:\test.mp4"
Start-Process -FilePath ffmpeg.exe -ArgumentList $args

But in both cases, FFmpeg won't start.

How can I put " in my arguments?

3
  • Escape the inner quotes with a backtick not backslashes. Backslashes error when I try that manually here. Commented Aug 28, 2015 at 17:23
  • -ArgumentList expects the parameters to be comma separated, try adding commas instead of spaces to $args. Commented Aug 28, 2015 at 17:25
  • like this? $args = " -f dshow, i video=integrated Camera, c:\test.mp4" ? Commented Aug 28, 2015 at 17:31

1 Answer 1

3

I would first urge caution that Start-Process may not be exactly what you desire. This will open a new process in a new command window (cmd).

I would encourage you to read the blog post PowerShell and external commands done right FYI.

However, there are a few ways to escape the quotes. One way to include double quotes in a string is to use a single quote to encapsulate the whole string for example:

$String = 'video="Integrated Camera"'

Alternatively you can escape with a backtick:

$String = "video=`"Integrated Camera`""

Another way would be to escape using double "s:

$String = "video=""Integrated Camera"""

The method you chose will be down to personal preference and the readability of your code. It's worth noting that the -ArgumentsList expects an array of strings.

Wrapping both of these up would give you something along the lines of:

$exe = "ffmpeg.exe"
$ffmpefArguments= "-f dshow i video=`"Integrated Camera`" c:\test.mp4"
&$exe $ffmpefArguments
Sign up to request clarification or add additional context in comments.

1 Comment

Nice! You got a good answer up before I could finish typing it. I just wanted to add that you can double up your double quotes within other double quotes instead of using the backtick, such as $ffshowargs = " -f dshow i video=""Integrated Camera"" c:\test.mp4" .Also, $args is an automatic variable used by PowerShell and I would strongly advise against using that like the OP as done.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.