Results 1 to 4 of 4

Thread: [Resolved]Command Line Error messages?

  1. #1

    Thread Starter
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765

    [Resolved]Command Line Error messages?

    Well, using the C# command line compiler thingie that comes with the .Net Framework (or is it the SDK?) and out of boredum I'm making a simple IDE in VB6 to save me from opening up a dos window each time to compile.

    Compiling is obviously easy, but if theres an error message and it doesn't compile, I was helping to retrieve the error messages and what not so that I can display them in my prog, but I dunno if the C# compiler supports that? Theres a bug report option, but that asks for user input.

    This threads abit of a cross between C#/VB/General PC.

    Thanks inadvance.
    Last edited by Pc_Madness; Jul 29th, 2004 at 07:45 AM.
    Don't Rate my posts.

  2. #2
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    So you want to redirect output from the commandline to your app? If so have a look at this code it might help.
    VB Code:
    1. 'Redirects output from console program to textbox.
    2. 'Requires two textboxes and one command button.
    3. 'Set MultiLine property of Text2 to true.
    4. '
    5. 'Original bcx version of this program was made by
    6. 'VB port was made by Jernej Simoncic <[email protected]>
    7. 'Visit Jernejs site at [url]http://www2.arnes.si/~sopjsimo/[/url]
    8. '
    9. 'Note: don't run plain DOS programs with this example
    10. 'under Windows 95,98 and ME, as the program freezes when
    11. 'execution of program is finnished.
    12.  
    13. Option Explicit
    14. Private Declare Function CreatePipe Lib "kernel32" (phReadPipe As Long, phWritePipe As Long, lpPipeAttributes As SECURITY_ATTRIBUTES, ByVal nSize As Long) As Long
    15. Private Declare Sub GetStartupInfo Lib "kernel32" Alias "GetStartupInfoA" (lpStartupInfo As STARTUPINFO)
    16. Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As Any, lpThreadAttributes As Any, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
    17. Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
    18. Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long
    19. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    20. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    21.  
    22. Private Type SECURITY_ATTRIBUTES
    23.   nLength As Long
    24.   lpSecurityDescriptor As Long
    25.   bInheritHandle As Long
    26. End Type
    27.  
    28. Private Type PROCESS_INFORMATION
    29.   hProcess As Long
    30.   hThread As Long
    31.   dwProcessId As Long
    32.   dwThreadId As Long
    33. End Type
    34.  
    35. Private Type STARTUPINFO
    36.   cb As Long
    37.   lpReserved As Long
    38.   lpDesktop As Long
    39.   lpTitle As Long
    40.   dwX As Long
    41.   dwY As Long
    42.   dwXSize As Long
    43.   dwYSize As Long
    44.   dwXCountChars As Long
    45.   dwYCountChars As Long
    46.   dwFillAttribute As Long
    47.   dwFlags As Long
    48.   wShowWindow As Integer
    49.   cbReserved2 As Integer
    50.   lpReserved2 As Byte
    51.   hStdInput As Long
    52.   hStdOutput As Long
    53.   hStdError As Long
    54. End Type
    55.  
    56. Private Type OVERLAPPED
    57.     ternal As Long
    58.     ternalHigh As Long
    59.     offset As Long
    60.     OffsetHigh As Long
    61.     hEvent As Long
    62. End Type
    63.  
    64. Private Const STARTF_USESHOWWINDOW = &H1
    65. Private Const STARTF_USESTDHANDLES = &H100
    66. Private Const SW_HIDE = 0
    67. Private Const EM_SETSEL = &HB1
    68. Private Const EM_REPLACESEL = &HC2
    69.  
    70. Private Sub Command1_Click()
    71.   Command1.Enabled = False
    72.   Redirect Text1.Text, Text2
    73.   Command1.Enabled = True
    74. End Sub
    75. Private Sub Form_Load()
    76.     Text1.Text = "ping"
    77. End Sub
    78. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    79.   If Command1.Enabled = False Then Cancel = True
    80. End Sub
    81.  
    82. Sub Redirect(cmdLine As String, objTarget As Object)
    83.   Dim i%, t$
    84.   Dim pa As SECURITY_ATTRIBUTES
    85.   Dim pra As SECURITY_ATTRIBUTES
    86.   Dim tra As SECURITY_ATTRIBUTES
    87.   Dim pi As PROCESS_INFORMATION
    88.   Dim sui As STARTUPINFO
    89.   Dim hRead As Long
    90.   Dim hWrite As Long
    91.   Dim bRead As Long
    92.   Dim lpBuffer(1024) As Byte
    93.   pa.nLength = Len(pa)
    94.   pa.lpSecurityDescriptor = 0
    95.   pa.bInheritHandle = True
    96.  
    97.   pra.nLength = Len(pra)
    98.   tra.nLength = Len(tra)
    99.  
    100.   If CreatePipe(hRead, hWrite, pa, 0) <> 0 Then
    101.     sui.cb = Len(sui)
    102.     GetStartupInfo sui
    103.     sui.hStdOutput = hWrite
    104.     sui.hStdError = hWrite
    105.     sui.dwFlags = STARTF_USESHOWWINDOW Or STARTF_USESTDHANDLES
    106.     sui.wShowWindow = SW_HIDE
    107.     If CreateProcess(vbNullString, cmdLine, pra, tra, True, 0, Null, vbNullString, sui, pi) <> 0 Then
    108.       SetWindowText objTarget.hwnd, ""
    109.       Do
    110.         Erase lpBuffer()
    111.         If ReadFile(hRead, lpBuffer(0), 1023, bRead, ByVal 0&) Then
    112.           SendMessage objTarget.hwnd, EM_SETSEL, -1, 0
    113.           SendMessage objTarget.hwnd, EM_REPLACESEL, False, lpBuffer(0)
    114.           DoEvents
    115.         Else
    116.           CloseHandle pi.hThread
    117.           CloseHandle pi.hProcess
    118.           Exit Do
    119.         End If
    120.         CloseHandle hWrite
    121.       Loop
    122.       CloseHandle hRead
    123.     End If
    124.   End If
    125. End Sub

  3. #3

    Thread Starter
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    Edit: Nevermind, something on my end. *doh*

    Thanks DeadEyes, I shall build a temple in your honour.
    Don't Rate my posts.

  4. #4
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    Make sure to include the good book AllAPI.net

    Any way this got be thinking, if you wanted to create an IDE for C# in order to learn C# what better way than to use C# to write the code.

    So I looked into how to do the same thing in .NET and here is the code in all it's tiny glory. ok it's in VB.net but you get the idea

    add a form with two textboxs and a command button
    VB Code:
    1. Imports System.IO
    2. Imports System.Diagnostics
    3. 'add this to the button click event
    4.         Dim p As Process
    5.         p = New Process()
    6.         p.StartInfo.FileName = "cmd.exe"
    7.         p.StartInfo.UseShellExecute = False
    8.         p.StartInfo.RedirectStandardInput = True
    9.         p.StartInfo.RedirectStandardOutput = True
    10.         p.StartInfo.CreateNoWindow = True
    11.         p.Start()
    12.         p.StandardInput.WriteLine(TextBox1.Text)
    13.         p.StandardInput.WriteLine("Exit")
    14.         TextBox2.Text = p.StandardOutput.ReadToEnd()
    15.         p.Close()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width