【发布时间】:2015-03-20 09:25:11
【问题描述】:
请对这个愚蠢的问题感到抱歉,我是 c# 的新手,我的 Vb 多年未受影响..
根据这篇文章:Process Start
这里是代码:
public static int Run(Action<string> output, TextReader input, string exe, params string[] args)
{
if (String.IsNullOrEmpty(exe))
throw new FileNotFoundException();
if (output == null)
throw new ArgumentNullException("output");
ProcessStartInfo psi = new ProcessStartInfo();
psi.UseShellExecute = false;
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.CreateNoWindow = true;
psi.ErrorDialog = false;
psi.WorkingDirectory = Environment.CurrentDirectory;
psi.FileName = FindExePath(exe); //see http://csharptest.net/?p=526
psi.Arguments = EscapeArguments(args); // see http://csharptest.net/?p=529
using (Process process = Process.Start(psi))
using (ManualResetEvent mreOut = new ManualResetEvent(false),
mreErr = new ManualResetEvent(false))
{
process.OutputDataReceived += (o, e) => { if (e.Data == null) mreOut.Set(); else output(e.Data); };
process.BeginOutputReadLine();
process.ErrorDataReceived += (o, e) => { if (e.Data == null) mreErr.Set(); else output(e.Data); };
process.BeginErrorReadLine();
string line;
while (input != null && null != (line = input.ReadLine()))
process.StandardInput.WriteLine(line);
process.StandardInput.Close();
process.WaitForExit();
mreOut.WaitOne();
mreErr.WaitOne();
return process.ExitCode;
}
}
...如何调用该函数?
我用这个修改了函数:
public static int Run(Action<string> output, TextReader input, string exe, string args)
...因为我已经知道exe路径并且我想直接将args作为直接字符串传递,但我不知道如何使用输出和输入变量。
顺便说一下,我了解功能但如何调用它? 澄清请帮我填写?这里:
Run(???, ???, "console.exe", " -someargs");
非常感谢一个代码示例...再次为我的愚蠢问题和我糟糕的英语感到抱歉。
问候
【问题讨论】:
-
请问可以缩进吗?
-
我没有错误,我只是不知道如何调用它,我只是编辑,请看一下,非常感谢!
-
@GuybrushThreepwood 代码仍然缺少缩进。 :-(
-
对不起,alexander,我刚刚批准并感谢您的帮助
标签: c# function calling-convention