我有一个控制台应用程序,它在启动时请求一个SourcePath。当我输入源路径时,它请求DestinationPath...当我输入DestinationPath时,它开始执行
我的问题是通过windows应用程序提供这些路径,这意味着我需要创建一个窗口表单应用程序,该应用程序将在一定时间间隔后自动将这些参数提供给控制台应用程序。
能不能实现.如果是,请帮忙..。非常紧急..。
噢..。我已经尝试了很多我无法粘贴的代码,除了一些用于启动应用程序的代码之外,其他代码都是.
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = @"C:\Program Files\Wondershare\PPT2Flash SDK\ppt2flash.exe";
psi.UseShellExecute = false;
psi.RedirectStandardError = true;
psi.RedirectStandardInput = true;
psi.CreateNoWindow = false;
psi.Arguments = input + ";" + output;
Process p = Process.Start(psi);和
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
CreateNoWindow = true,
FileName = @"C:\Program Files\Wondershare\PPT2Flash SDK\ppt2flash.exe",
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
}
};
if (process.Start())
{
Redirect(process.StandardError, text);
Redirect(process.StandardOutput, text);
MessageBox.Show(text);
}
private void Redirect(StreamReader input, string output)
{
new Thread(a =>{var buffer = new char[1];
while (input.Read(buffer, 0, 1) > 0)
{
output += new string(buffer);
};
}).Start();
}但似乎什么都起不到作用
发布于 2013-01-10 10:36:19
可以将参数添加到ProcessStartInfo中,如下所示:
ProcessStartInfo psi = new ProcessStartInfo(@"C:\MyConsoleApp.exe",
@"C:\MyLocationAsFirstParamter C:\MyOtherLocationAsSecondParameter");
Process p = Process.Start(psi);这将启动带有2个参数的控制台应用程序。现在,在您的控制台应用程序中,您可以使用
static void Main(string[] args)字符串数组args包含参数,现在您所要做的就是在应用程序启动时获取它们。
if (args == null || args.Length < 2)
{
//the arguments are not passed correctly, or not at all
}
else
{
try
{
yourFirstVariable = args[0];
yourSecondVariable = args[1];
}
catch(Exception e)
{
Console.WriteLine("Something went wrong with setting the variables.")
Console.WriteLine(e.Message);
}
}这可能是或可能不是您需要的确切代码,但至少会让您了解如何完成您想要的任务。
https://stackoverflow.com/questions/14255084
复制相似问题