0

This is probably a simple question that I'm just not figuring out how to word correctly lol. Anyway, allow me to describe my problem.

So I have written a program that helps users manage their installation of their program. For obvious reasons, I offer a GUI and command-line access to this app (the GUI is in WPF).

Anyway, so my problem is with outputting a bunch of text to the command line. Here's my code:

    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");
        }
    }

It seems pretty straightforward, doesn't it? I'd think the result would be pretty obvious. However, when I go into PowerShell and access it, this is what I get:

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

The formatting comes out all okay and whatever, but the problem is that the top line is being written into the next command input. As I start typing in more commands and whatnot, it ends up overwriting lines. (i.e.:

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)

)

What do I do so that it writes the output and then displays the whole "PS C:\Users\...\bin\Release>" thing afterwards?

1 Answer 1

1

Your issue is that your app immediately (as part of the WPF startup code) releases the console. Then cmd.exe gets ready to accept more input by printing the prompt.

Then you reattach to the console and start outputting your help text. But cmd.exe doesn't know about that, so the console gets garbled.

I suggest fixing it by making two programs. Keep your WPF app as is, but add a small console application in front. The console application prints the text you want (if needed) and then starts your WPF app.

Sign up to request clarification or add additional context in comments.

1 Comment

Hmm... I suppose that's only reasonable, isn't it? Really stinks, though, I kind of wanted to keep it in one app. But alrighty, I guess I'll be exploring my options in this front.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.