Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 带有控制台应用程序的Windows窗体应用程序_C#_Winforms_C# 3.0_Console Application - Fatal编程技术网

C# 带有控制台应用程序的Windows窗体应用程序

C# 带有控制台应用程序的Windows窗体应用程序,c#,winforms,c#-3.0,console-application,C#,Winforms,C# 3.0,Console Application,我有一个控制台应用程序,它在启动时请求源路径。。当我输入源路径时,它要求DestinationPath。。。当我进入DestinationPath时,它开始执行 我的问题是通过windows应用程序提供这些路径,这意味着我需要创建一个窗口窗体应用程序,该应用程序将在特定时间间隔后自动向控制台应用程序提供这些参数 它能不能实现。。。如果是,请帮忙。。。非常紧急 哦。。 我已经尝试了很多代码,我不能粘贴听到所有,但我用来启动应用程序的一些是 ProcessStartInfo psi

我有一个控制台应用程序,它在启动时请求源路径。。当我输入源路径时,它要求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);


但似乎没有任何效果

您可以向ProcessStartInfo中添加如下参数:

 ProcessStartInfo psi = new ProcessStartInfo(@"C:\MyConsoleApp.exe",
     @"C:\MyLocationAsFirstParamter C:\MyOtherLocationAsSecondParameter");
 Process p = Process.Start(psi);
这将使用2个参数启动console应用程序。 现在,在您的控制台应用程序中,您拥有

 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);
    }
}
if(args==null | | args.Length<2)
{
//参数传递不正确,或者根本不正确
}
其他的
{
尝试
{
yourFirstVariable=args[0];
yourSecondVariable=args[1];
}
捕获(例外e)
{
WriteLine(“设置变量时出错了。”)
控制台写入线(e.Message);
}
}

这可能是您所需要的确切代码,也可能不是,但至少可以让您了解如何实现您的目标。

这是可以实现的。但我们无法帮助您了解更多详细信息,除非您告诉我们您尝试了什么。我添加了我尝试的任何帮助。因此,如果我理解正确,您需要在从表单启动控制台应用程序时提供控制台应用程序参数?你想让它自动化吗?是的。。。这就是我想要的。。可能吗?@ryadavilli我不是在问密码。。我只是想问一下技巧或是对过程的一点解释。。。这将是有益的是,此代码可能工作,但不适合我的应用程序。。因为我可以更改的地方是我的窗体应用程序,。。。。控制台应用程序无法修改,因为我只能使用其.exe。。。这是我的主要问题你有什么建议吗。。如果是,请提供帮助这是非常紧迫的,因此在构建控制台应用程序之前,您没有控制台应用程序的实际源代码?是的,您是对的,这就是为什么我需要像我解释的那样做的原因。在这种情况下,我恐怕不知道答案。但是您确定build console.exe不支持任何启动参数吗?或者console.exe是否有任何公共文档可供我阅读?
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);
    }
}