process.start()参数 [英] process.start() arguments

查看:201
本文介绍了process.start()参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我做下面的命令,它会工作很好

  ffmpeg -f image2 -i frame%d.jpg -vcodec mpeg4 -b 800k video.avi 

当我尝试在c#中使用流程类,参数,它加载ffmpeg在控制台窗口,然后消失像往常一样。但是,当我尝试使用参数,如上所述,格式完全相同...它不工作! ffmpeg仍然加载,然而由于控制台窗口关闭这么快我无法确定错误是什么:/

 进程ffmpeg = (); 
ffmpeg.StartInfo.FileName = path +//+ffmpeg.exe;
ffmpeg.StartInfo.Arguments =-f image2 -i frame%d.jpg -vcodec mpeg4 -b 800k video.avi;
ffmpeg.Start();

任何人都知道为什么会这样?为什么命令从dos工作,然后使用c#无法工作,即使参数完全相同?

解决方案

尝试完全限定参数中的文件名 - I注意你正在指定FileName部分中的路径,因此可能该进程正在其他地方启动,然后找不到参数并导致错误。



工作,然后将 WorkingDirectory 属性设置为


实际上,如果UserName和Password是
提供的,则WorkingDirectory属性必须设置
。如果未设置属性,
默认工作目录为
%SYSTEMROOT%\system32。



when i do the following command into dos it will work fine

ffmpeg -f image2 -i frame%d.jpg -vcodec mpeg4 -b 800k video.avi

When I try to use the process class in c#, without the arguments, it loads ffmpeg in a console window then dissapears like usual. However, when I try to use the argument as I do above, formatted exactly the same...it doesn't work! ffmpeg still loads, however since the console window closes so fast I cannot determine what the error is :/

Process ffmpeg = new Process();
ffmpeg.StartInfo.FileName = path + "//" + "ffmpeg.exe";
ffmpeg.StartInfo.Arguments = " -f image2 -i frame%d.jpg -vcodec mpeg4 -b 800k video.avi";
ffmpeg.Start();

Any one know why this is? Why would the command work from dos and then fail to work using c# even when the arguments are exactly the same? I've used this method before for many things and never encountered this.

解决方案

Try fully qualifying the filenames in the arguments - I notice you're specifying the path in the FileName part, so it's possible that the process is being started elsewhere, then not finding the arguments and causing an error.

If that works, then setting the WorkingDirectory property on the StartInfo may be of use.

Actually, according to the link

The WorkingDirectory property must be set if UserName and Password are provided. If the property is not set, the default working directory is %SYSTEMROOT%\system32.

这篇关于process.start()参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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