我写了一个桌面应用程序,想让它既可以双击运行又支持命令行方式运行于是我改写了下Main函数如下:
static void Main(string[] args)
{
if (args.Length == 0)
{
Application.Run(new PrintView());
}
else
{
System.Console.WriteLine("hello");
}
}这样的话,双击没有问题,但在DOS下却打印不出信息,有人知道如何解决吗?
static void Main(string[] args)
{
if (args.Length == 0)
{
Application.Run(new PrintView());
}
else
{
System.Console.WriteLine("hello");
}
}这样的话,双击没有问题,但在DOS下却打印不出信息,有人知道如何解决吗?
System.Console.WriteLine("hello");
是不会在那个"DOS"窗口中显示信息的.只有控制台程序可以在DOS窗口里显示内容.
你如果是建立的桌面应用程序,那么用System.Console是不会在DOS的窗口中显示信息的,
除非你建立控制台程序才可以.
我现在想知道的是原因,或者怎样才能做一个程序,即有画面(双击运行)又可以命令行运行(打印信息),我想寻求一个解决解决的途径。
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(cmdText);
p.StandardInput.WriteLine("exit");
while(!p.HasExited)
{
p.WaitForExit();
}
p.Close();
你照着上面的例子再改一下试试吧