管道过程输出到新过程 [英] Piping process output to new process

查看:97
本文介绍了管道过程输出到新过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将rtmpdump进程的输出传递到ffmpeg时遇到问题,我认为问题在于我的进程正在窃取rtmpdump的输出.

I am having issues piping the output from the rtmpdump process to ffmpeg and I believe the issue is my process is stealing the output of rtmpdump.

在我的研究中,我听说过尝试使用cmd.exe进程并在其中运行rtmpdump.exe作为/C命令,但是这个问题是我没有参考由此产生的rtmpdump.exe进程,而且我需要能够在我的程序中管理多个rtmpdump进程,并有时有选择地杀死某些进程.

In my research I have heard of trying to use a cmd.exe process and run rtmpdump.exe as a /C command within that, but this issue is I lose reference to the rtmpdump.exe process that is spawned from that, and I need to be able to manage multiple rtmpdump processes within my program and selectively kill certain ones at times.

我最初尝试过类似以下的简单操作:

I initially tried something simple like this:

var p = new Process();
p.StartInfo.FileName = "rtmpdump.exe";
p.StartInfo.Arguments = "-v -r rtmp://somehost.com/app-name -o - | ffmpeg.exe -loglevel quiet -i - -c:v copy -c:a libvo_aacenc -b:a 128k \"test.mp4\"";

这根本不起作用.

以"cmd.exe"作为初始过程:

with "cmd.exe" as initial process:

var p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/C rtmpdump.exe -v -r rtmp://somehost.com/app-name -o - | ffmpeg.exe -loglevel quiet -i - -c:v copy -c:a libvo_aacenc -b:a 128k \"test.mp4\"";

这使我更接近需要它启动rtmpdump进程并重定向到ffmpeg,但是现在"p"将引用一个不存在的"cmd.exe"进程,该进程运行了先启动rtmpdump然后启动"cmd.exe"的命令终止.

This gets me closer to what I need it starts a rtmpdump process and redirects to ffmpeg, but now "p" will reference a non existent "cmd.exe" process that ran the command to start rtmpdump then "cmd.exe" terminates.

我唯一关心的是能够保留所创建的rtmpdump.exe进程的引用. ffmpeg将在rtmpdump关闭其进程后自行终止.

My only concern is being able to keep reference of the rtmpdump.exe processes created. ffmpeg will self terminate after rtmpdump closes its process can be ignored.

如果问题不清楚.我正在尝试将rtmpdump的输出传递给ffmpeg.使用重定向运算符|不能正常地将其作为命令参数的一部分来执行.并无法按照需要使用"cmd.exe"进程.

If the question wasn't clear. I am trying to pipe the output of rtmpdump to ffmpeg. normal way of doing it as part of the command argument are not working using the redirection operator |. and using a "cmd.exe" process does not work as needed.

推荐答案

提出一个简单的解决方案.

Came up with a simple solution.

使用CMD流程作为开始流程.

Using the the CMD process as your starting process.

var p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/C rtmpdump.exe -v -r rtmp://somehost.com/app-name -o - |       ffmpeg.exe -loglevel quiet -i - -c:v copy -c:a libvo_aacenc -b:a 128k \"test.mp4\"";
test.Start();

并在启动进程后立即使用此代码,以获取最后创建的rtmpdump进程.

And using this bit of code right after starting the process to get the last created rtmpdump process.

Process[] allDumps = Process.GetProcessesByName("rtmpdump"); // get all rtmp processes
if (allDumps.Any())
{
    Process newestProcess = allDumps.OrderByDescending(x => x.StartTime).First(); // get the last one created     
    // Add the newly captured process to your list of processes for use later.
}

这篇关于管道过程输出到新过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆