如何将参数传递给在C#中的另一个进程 [英] How to pass parameters to another process in c#
问题描述
我刚刚创建了具有以下code启动进程对应用程序
字串[] args = {A,B};
的Process.Start(C:\\ \\ DEMO.EXE的string.join(,参数));
我希望能够从这个应用程序,我启动的进程传递的参数。
在那里我有我所启动的进程的项目进入参数?
我试图把它们放在
静态无效的主要(字串[] args){...
,但它们不以其它形式提供。
感谢您的帮助。
进程p =新工艺();
p.StartInfo.FileName =DEMO.EXE;
p.StartInfo.Arguments =一个B;
p.Start();
或
的Process.Start(DEMO.EXE,A B);
在DEMO.EXE
静态无效的主要(字串[] args)
{
Console.WriteLine(参数[0]);
Console.WriteLine(参数[1]);
}
您问到如何保存这些PARAMS。您可以创建静态属性新类,并保存这些PARAMS那里。
类ParamHolder
{
公共静态字符串[] {PARAMS获得;组;}
}
和主
静态无效的主要(字串[] args)
{
ParamHolder.Params = ARGS;
}
让PARAMS在程序中使用的任何地方:
Console.WriteLine(ConsoleParamHolder.Params [0]);
Console.WriteLine(ConsoleParamHolder.Params [1]);
等。
I just created an application that launches processes with the following code
string [] args = {"a", "b"};
Process.Start ("C: \ \ demo.exe" String.Join ("", args));
I would like to be able to pass the parameters from this application to the process I've launched.
where I have to enter the parameters in the project of the process that I've launched? I tried to put them in
static void Main (string [] args) {...
but they are not available in other forms. thanks for the help
Process p= new Process();
p.StartInfo.FileName = "demo.exe";
p.StartInfo.Arguments = "a b";
p.Start();
or
Process.Start("demo.exe", "a b");
in demo.exe
static void Main (string [] args)
{
Console.WriteLine(args[0]);
Console.WriteLine(args[1]);
}
You asked how to save these params. You can create new class with static properties and save these params there.
class ParamHolder
{
public static string[] Params { get; set;}
}
and in main
static void Main (string [] args)
{
ParamHolder.Params = args;
}
to get params in any place of your program use:
Console.WriteLine(ConsoleParamHolder.Params[0]);
Console.WriteLine(ConsoleParamHolder.Params[1]);
etc.
这篇关于如何将参数传递给在C#中的另一个进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!