2

How can I send the command "q" to a FFMPEG process with C#?
I tried it like this:

var p = Process.GetProcessesByName("ffmpeg").FirstOrDefault();

if (p != null)
{
    p.StandardInput.Write("q");
}

But I got this error:

Error message in Visual Studio

Nicke Manarin
  • 3,026
  • 4
  • 37
  • 79
thiago.adriano26
  • 1,491
  • 3
  • 14
  • 19

1 Answers1

4

You can use the SendMessage call of the user32 api.

[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter,          string lpszClass, string lpszWindow);

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);

static void Send(string message)
{
    var notepads = Process.GetProcessesByName("notepad");
    
    if (notepads.Length == 0)
        return;

    if (notepads[0] != null)
    {
        var child = FindWindowEx(notepads[0].MainWindowHandle, new IntPtr(0), "Edit", null);
        SendMessage(child, 0x000C, 0, message);
    }
}

Change it as you need. I'm not sure it would work for your situation, but it's always good to try.

Goodluck.

Nicke Manarin
  • 3,026
  • 4
  • 37
  • 79
Slashy
  • 1,841
  • 3
  • 23
  • 42