给 用System.Diagnostics.Process启动的进程 传递参数,新进程怎么接收参数?

BlueLoves 2004-06-21 03:36:28
在一个程序里边启动另一个程序:
System.Diagnostics.Process pro=new System.Diagnostics.Process();
pro.StartInfo.FileName = System.IO.Directory.GetCurrentDirectory()+ @"\MyProg.exe";
pro.StartInfo.UseShellExecute = false;
pro.StartInfo.Arguments = "My Arg";
pro.Start();
MyProg.exe启动之后,怎么接收Arguments包含的参数?
好像Main函数里边没有地方可以接收参数啊
...全文
490 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
BlueLoves 2004-06-21
  • 打赏
  • 举报
回复
好的,问题解决,
太谢谢了,原来给main函数增加参数就可以了。
CMIC 2004-06-21
  • 打赏
  • 举报
回复
在MyProg.exe的Main函数中可以设置接受参数
例子:
-----------

在此示例中,程序在运行时采用一个参数,将该参数转换为一个长数字,并计算该数字的阶乘。如果没有提供参数,则程序发出一条消息来解释程序的正确用法。

// Factorial_main.cs
// arguments: 3
using System;
public class Factorial
{
public static long Fac(long i)
{
return ((i <= 1) ? 1 : (i * Fac(i-1)));
}
}

class MainClass
{
public static int Main(string[] args)
{
// Test if input arguments were supplied:
if (args.Length == 0)
{
Console.WriteLine("Please enter a numeric argument.");
Console.WriteLine("Usage: Factorial <num>");
return 1;
}

// Convert the input arguments to numbers:
try
{
long num = long.Parse(args[0]);
Console.WriteLine("The Factorial of {0} is {1}.",
num, Factorial.Fac(num));
return 0;
}
catch (System.FormatException)
{
Console.WriteLine("Please enter a numeric argument.");
Console.WriteLine("Usage: Factorial <num>");
return 1;
}
}
}

110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧