为何不能取得命令行参数?

tumin999 2003-04-25 12:55:22
// ProcessTest.cs
using System;
using System.Diagnostics;

public class Hello4
{
public static int Main(string[] args)
{
Process myProcess1 = new Process();
myProcess1.StartInfo.FileName = "notepad";
myProcess1.StartInfo.Arguments = "c:\\boot.ini";
myProcess1.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
myProcess1.Start();

Process[] myProcesses;
myProcesses = Process.GetProcessesByName ("notepad");
foreach(Process myProcess in myProcesses)
{
Console.WriteLine ("_" + myProcess.ProcessName + "_");
Console.WriteLine ("_" + myProcess.StartInfo.Arguments + "_"); /* 为什么为空,而不是c:\boot.ini */
Console.WriteLine ("_" + myProcess.StartInfo.FileName + "_"); /* 也为空??? */
}

return 0;
}
}
...全文
53 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Knight94 2003-04-25
  • 打赏
  • 举报
回复
StartInfo应该是传给进程Start,进程运行以后,要获得信息应该用myProcess.MainModule,例如获得文件名用myProcess.MainModule.FileName。

110,549

社区成员

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

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

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