【发布时间】:2018-01-18 06:55:58
【问题描述】:
这可能是一个简单的问题,我只是不知道如何正确地用词大声笑。无论如何,请允许我描述一下我的问题。
所以我编写了一个程序来帮助用户管理他们的程序安装。出于显而易见的原因,我提供了对该应用程序的 GUI 和命令行访问(GUI 位于 WPF 中)。
无论如何,我的问题是将一堆文本输出到命令行。这是我的代码:
void WriteHelp()
{
// Attach to console to write out to it
if (AttachConsole(-1))
{
Console.WriteLine("InstallAssist helps maintain your Shine Calendar installation.");
Console.WriteLine("Version " + VERSION_STRING + " (" + VERSION_ID + ")");
Console.WriteLine("Written by Jayke R. Huempfner. Copyright 2018.");
Console.WriteLine();
Console.WriteLine("Can be accessed through GUI or by using the arguments below:");
Console.WriteLine();
Console.WriteLine("Argument Action");
Console.WriteLine("-------- ------");
Console.WriteLine("-about (-a) Displays version/system info");
Console.WriteLine("-hardreset (-hr) Perform a hard reset");
Console.WriteLine("-help (-?) Displays this help page.");
Console.WriteLine("-info (-i) Displays version/system info");
Console.WriteLine("-quiet (-q) Quiet mode, don't display GUI");
Console.WriteLine("-reset (-e) Display reset options GUI");
Console.WriteLine("-skipconfirm (-sc) Skip confirmation GUI screen");
Console.WriteLine("-softreset (-s) Perform a soft reset");
Console.WriteLine("-uninstall (-u) Uninstall, keeping user data");
Console.WriteLine("-uninstallall (-ua) Uninstall, deleting user data");
Console.WriteLine();
Console.WriteLine("More information available online at:");
Console.WriteLine("https://shinecalendar.com/help/advanced");
}
}
看起来很简单,不是吗?我想结果会很明显。但是,当我进入 PowerShell 并访问它时,我得到的是:
PS C:\Users\jacob\Documents\Visual Studio 2017\Projects\ShineCalendar\ShineWin\bin\Release> .\InstallAssist.exe -help
PS C:\Users\jacob\Documents\Visual Studio 2017\Projects\ShineCalendar\ShineWin\bin\Release> InstallAssist helps maintain your Shine Calendar installation.
Version 0.8.0 (800)
Written by Jayke R. Huempfner. Copyright 2018.
Can be accessed through GUI or by using the arguments below:
Argument Action
-------- ------
-about (-a) Displays version/system info
-hardreset (-hr) Perform a hard reset
-help (-?) Displays this help page.
-info (-i) Displays version/system info
-quiet (-q) Quiet mode, don't display GUI
-reset (-e) Display reset options GUI
-skipconfirm (-sc) Skip confirmation GUI screen
-softreset (-s) Perform a soft reset
-uninstall (-u) Uninstall, keeping user data
-uninstallall (-ua) Uninstall, deleting user data
More information available online at:
https://shinecalendar.com/help/advanced
格式输出一切正常,但问题是顶行正在写入下一个命令输入。当我开始输入更多命令等等时,它最终会覆盖行。 (即:
PS C:\Users\jacob\Documents\Visual Studio 2017\Projects\ShineCalendar\ShineWin\bin\Release> .\InstallAssist.exe -help
PS C:\Users\jacob\Documents\Visual Studio 2017\Projects\ShineCalendar\ShineWin\bin\Release> dir
lation.
Version 0.8.0 (800)
Directory: C:\Users\jacob\Documents\Visual Studio 2017\Projects\ShineCalendar\ShineWin\bin\Release
Can be accessed through GUI or by using the arguments below:
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 9/9/2016 2:59 PM 77312 CsvHelper.dll
... (rest omitted)
)
我该怎么做才能写入输出,然后显示整个"PS C:\Users\<b>...</b>\bin\Release>"?
【问题讨论】:
标签: c# powershell output command-line-interface