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

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

问题描述

当我在 dos 中执行以下命令时,它会正常工作

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

当我尝试在 c# 中使用进程类时,如果没有参数,它会在控制台窗口中加载 ffmpeg,然后像往常一样消失.但是,当我尝试像上面那样使用参数时,格式完全相同......它不起作用!ffmpeg 仍然加载,但是由于控制台窗口关闭得如此之快,我无法确定错误是什么:/

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();

有人知道这是为什么吗?为什么命令会从 dos 工作,然后即使参数完全相同,也无法使用 c# 工作?我以前用过这种方法做很多事情,从来没有遇到过这种情况.

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.

推荐答案

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

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.

如果可行,则设置 WorkingDirectory StartInfo 上的属性可能有用.

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

其实,根据链接

WorkingDirectory 属性必须如果用户名和密码是假如.如果未设置该属性,默认工作目录是%SYSTEMROOT%system32.

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天全站免登陆