使用多个参数C#应用程序启动 [英] C# Launch application with multiple arguments

查看:183
本文介绍了使用多个参数C#应用程序启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力,开始从C#应用程序的应用程序,但它无法正常启动。从CMD应用加上参数推出了输出然后最小化到系统托盘中的应用程序的小窗口。

I have been trying to start an application from a C# application but it fails to start properly. From the cmd the application plus the arguments launch a small window showing the output then the application in minimized to the system tray.

启动从C#应用程序使用下面出现在任务管理器,但没有别的,没有输出窗口,没有系统托盘图标结果在这个过程中的代码的应用程序。可能是什么问题?

Launching the application from the C# application using the code below results in the process appearing in the task manager but nothing else, no output window, no system tray icon. What could be the issue?

    myProcess.StartInfo.FileName = ...;
    myProcess.StartInfo.Arguments = ...;
    myProcess.Start();



还试图通过以下

also tried passing the following

    myProcess.StartInfo.RedirectStandardOutput = true; //tried both
    myProcess.StartInfo.UseShellExecute = false; //tried both 
    myProcess.StartInfo.CreateNoWindow = false;



使用

using

    Process.Start(Filename, args)

也没有工作。 。真的很感激,关于如何解决这个任何帮助。

also did not work. Would really appreciate any help on how to tackle this.

更​​新:
我认为这个问题也许多个参数是要传递到过程

UPDATE: I think the issue maybe the multiple arguments that are to be passed to the process

RunMode=Server;CompanyDataBase=dbname;UserName=user;PassWord=passwd;DbUserName=dbu;Server=localhost;LanguageCode=9

关于

推荐答案

我没有看到你的代码中的任何错误。我写了一个小程序,打印出其args设置为控制台

I don't see any mistake in your code. I have written a little program that prints out its args to the console

static void Main (string[] args)
{
     foreach (string s in args)
         Console.WriteLine(s);
     Console.Read(); // Just to see the output
}

和以后,我把它放在C: ,作为应用PrintingArgs.exe的名字,所以我写了另外一个,执行第一:

and then I have put it in C:, being the name of the app "PrintingArgs.exe", so I have written another one that executes the first:

Process p = new Process();
p.StartInfo.FileName = "C:\\PrintingArgs.exe";
p.StartInfo.Arguments = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18";
p.Start();

这给我的号码列表中所需的输出。调用PrintingArgs退出,因为它reachs p.Start()的应用程序,这可以通过使用 p.WaitForExit()来避免; 或只是控制台。阅读();
我也都用了 p.UseShellExecute p.CreateNoWindow 。只有在情况下

this gives me the desired output of the list of numbers. The app that calls PrintingArgs exits as it reachs p.Start(), this could be avoided by using p.WaitForExit(); or just Console.Read();. Also I have used both p.UseShellExecute and p.CreateNoWindow. Only in the case that

p.UseShellExecute = false;
p.CreateNoWindow = true;



使得PrintingArgs应用程序不显示一个窗口(即使我只放 p.CreateNoWindow = TRUE 它显示一个窗口)。

现在说到我心里,也许你正在过ARGS以错误的方式并使得其他程序失败inmediately关闭,或者你没有指向正确的文件。检查路径和名称,以便找到你可以忽略任何错误。
此外,使用

Now it comes to my mind that maybe your are passing the args in a wrong way and makes the other program to fail and close inmediately, or maybe you are not pointing to the right file. Check paths and names, in order to find any mistake you could omit. Also, using

 Process.Start(fileName, args);



不使用你设置了StartInfo的进入你的流程实例的信息。

does not uses the info you set up with StartInfo into your Process instance.

希望这会有所帮助,
关于

Hope this will help, regards

这篇关于使用多个参数C#应用程序启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆