0

How do I "talk back" to the command line? Using Console.Writeline() doesn't do it. Therefore if the user drags and drops a text file with incorrect formatting it gives no error message, just closes without producing any output.

 Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As
 System.EventArgs) Handles MyBase.Load
         ServicePointManager.SecurityProtocol = DirectCast(3072, SecurityProtocolType)
 
         'Get command line arguments
         Dim lstArgs As List(Of String) = Environment.GetCommandLineArgs.ToList
 
         '1st argument is the application itself, so we can remove that
         'and just look at the actual arguments, if any
         lstArgs.RemoveAt(0)
 
         'If 1 argument is present, process input file
         If lstArgs.Count = 1 Then
             If File.Exists(lstArgs(0)) Then
                 Console.WriteLine("Reading from " & lstArgs(0) & "...")
                 DrawCommandLine(File.ReadAllText(lstArgs(0)))
             End If
 
             'If 2 are present, input file and output filename have been stated
             'Filename is optional
         ElseIf lstArgs.Count = 2 Then
             If File.Exists(lstArgs(0)) Then
                 strCurrFilename = lstArgs(1)
 
                 Console.WriteLine("Reading from " & lstArgs(0) & "...")
                 Console.WriteLine("Filename will be " & lstArgs(0))
                 DrawCommandLine(File.ReadAllText(lstArgs(0))) 'File name specified
             End If
 
             'No arguments present, user isn't using cmd. Open GUI like normal.
         End If

     End Sub
Adam
  • 11
  • 2
  • Provided code/example isn't good enough to understand your problem. You are dragging on your Exe? Or into your window? Make the smallest demo code you can think of, post it completely and describe exactly what you are doing. – Sven Bardos Jul 28 '20 at 21:08
  • what is "DrawCommandLine()" doing? – Sven Bardos Jul 28 '20 at 21:09
  • WinForms don't have console - so you need to attach one as shown in duplicate (https://stackoverflow.com/questions/4362111/how-do-i-show-a-console-output-window-in-a-forms-application) I selected. If it is not what you are asking please [edit] question to clarify. Note that it may be easier to show form from console app rather than other way around. – Alexei Levenkov Jul 28 '20 at 21:21
  • Looking at your code here, it's pretty unclear exactly what you are trying to do. Are you hoping to drop say a text file on the console and have it print the contents? Console.WriteLine isn't going to work from the context of a windows form, do you need write to the console or can you just output you text to a winforms control? – Hursey Jul 28 '20 at 22:26

0 Answers0