我想要一个在arg中传递的控制台应用程序,以便能够调用自己传递最初发送的同一命令arg。
如果我试试这个
static void Main(string[] args)
{
Assembly ass = System.Reflection.Assembly.GetExecutingAssembly();
string cmd = Environment.CommandLine;
Process again = new Process();
again.StartInfo.FileName = ass.Location;
again.StartInfo.Arguments = args[0];
Console.WriteLine("Running with: " + args[0]);
System.Threading.Thread.Sleep(10000);
again.Start();
return;
}
初始调用打印“运行:Argument1”但第二次调用失败,因为args数组为空。
答案 0 :(得分:3)
适合我。我编译完全这段代码:
using System;
using System.Diagnostics;
using System.Reflection;
class Test
{
static void Main(string[] args)
{
Assembly ass = System.Reflection.Assembly.GetExecutingAssembly();
string cmd = Environment.CommandLine;
Process again = new Process();
again.StartInfo.FileName = ass.Location;
again.StartInfo.Arguments = args[0];
Console.WriteLine("Running with: " + args[0]);
System.Threading.Thread.Sleep(1000);
again.Start();
return;
}
}
使用命令行:
csc Test.cs
然后将其作为:
运行Test.exe hello
...它以递归方式启动了额外的进程,每个进程都打印了“Running with:hello”。