[英]Windows Form Application with Console Application
I have a console application that asks for a SourcePath when started.. when I enter the Source Path, It asks for DestinationPath ... when i enter DestinationPath it starts some execution 我有一个控制台应用程序,它在启动时会询问SourcePath 。当我输入Source Path时,会询问DestinationPath ...当我进入DestinationPath时,它将开始执行
My Problem is to Supply these path via a windows application, means i need to create a window form application that will supply these parameters to the console application automatiocally after certain time interval 我的问题是通过Windows应用程序提供这些路径,这意味着我需要创建一个窗口表单应用程序,该应用程序将在一定时间间隔后自动将这些参数提供给控制台应用程序
can it be achieved or not... if yes, plese help... its very Urgent... 是否可以实现...如果是,请帮助...非常紧急...
ohh.. I have tried a lot of code that i can not paste hear all but some that i use to start the application are... 哦。我尝试了很多我无法粘贴的代码,但我用来启动应用程序的一些代码是...
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);
and 和
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();
}
but nothing seems to be working 但似乎没有任何作用
You can add parameters to your ProcessStartInfo like this: 您可以像这样将参数添加到您的ProcessStartInfo中:
ProcessStartInfo psi = new ProcessStartInfo(@"C:\MyConsoleApp.exe",
@"C:\MyLocationAsFirstParamter C:\MyOtherLocationAsSecondParameter");
Process p = Process.Start(psi);
this will startup the console app with 2 parameters. 这将使用2个参数启动控制台应用程序。 Now in your console app you have the
现在,在控制台应用程序中,
static void Main(string[] args)
the string array args is what contains the parameters, now all you have to do is get them when your app starts. 字符串数组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);
}
}
This may or may not be the exact code that you need, but at least will give you an insight in how to accomplish what you want. 这可能不是您所需要的确切代码,但至少可以使您深入了解如何完成所需的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.