Results 1 to 30 of 30

Thread: Command Prompt

  1. #1

    Thread Starter
    Banned ThaRubby's Avatar
    Join Date
    Apr 2005
    Location
    127.0.0.1
    Posts
    356

    Command Prompt

    How can i open a command prompt run multiple commands and put the output of the command(s) into a text file or something?

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Command Prompt

    You might want to create a batch (.bat/.cmd) file that contains your commands, and then shell the batch file.

  3. #3

    Thread Starter
    Banned ThaRubby's Avatar
    Join Date
    Apr 2005
    Location
    127.0.0.1
    Posts
    356

    Re: Command Prompt

    I know how to echo text into text files but how would i echo the output into the text file o.0

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Command Prompt

    To get the output of a batch file in a file you can use this :

    VB Code:
    1. Shell "C:\batch file.bat > C:\out.txt", vbNormal


    Has someone helped you? Then you can Rate their helpful post.

  5. #5

    Thread Starter
    Banned ThaRubby's Avatar
    Join Date
    Apr 2005
    Location
    127.0.0.1
    Posts
    356

    Re: Command Prompt

    Awesome thats pretty good and useable but is it also posible to get the command issued...bacily everything that happened?

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Command Prompt

    Instead of a batch file you can just pass the DOS commands directly. Then output the results to a file.
    Its not that hard.

    This example will pass the DIR command, enter C:\, and output the directory listing to the file C:\Dir.txt
    The /K switch is to keep the DOS window open but you can change it to the /C to close it. Also, SW_HIDE to make
    it totally transparent to the user.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
    4. ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    5.  
    6. Private Const SW_HIDE As Long = 0
    7. Private Const SW_SHOWNORMAL As Long = 1
    8.  
    9. Private Sub Command1_Click()
    10.     ShellExecute Me.hwnd, "Open", "C:\Windows\System32\CMD.exe", " /K Dir C:\  > C:\Dir.txt", "C:\", SW_SHOWNORMAL
    11. End Sub
    Note: you would want to use the GetSystemDirectory API to dynamically get the directory where the CMD.EXE program is located.

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Command Prompt

    Quote Originally Posted by RobDog888
    you would want to use the GetSystemDirectory API to dynamically get the directory where the CMD.EXE program is located.
    Well that would require that cmd.exe actually is in that directory, and on a Win9x/ME box cmd.exe doesn't even exist. What you can use instead is Environ("COMSPEC").

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Command Prompt

    How do you append command output to the same file, though?

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Command Prompt

    Quote Originally Posted by dglienna
    How do you append command output to the same file, though?
    You use >> instead of the > redirection character.

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Command Prompt

    Quote Originally Posted by Joacim Andersson
    Well that would require that cmd.exe actually is in that directory, and on a Win9x/ME box cmd.exe doesn't even exist. What you can use instead is Environ("COMSPEC").
    At the end of my post I added a Note that you can get the CMD.exe location dynamically using the GetSystemDirectory API.

    I dont like to rely on the environ variable since it can be changed or deleted by the user.

    Quote Originally Posted by dgleinna
    How do you append command output to the same file, though?
    You simple use the append mode of file output instead of the output mode.

    Output: >
    Append: >>

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    Banned ThaRubby's Avatar
    Join Date
    Apr 2005
    Location
    127.0.0.1
    Posts
    356

    Re: Command Prompt

    Anyway I can send the output into a string and into a Textbox?

    I tried this it was pretty dumb heh..

    Private Sub Form_Load()
    Dim Test As String
    Test = Shell("C:\file.bat > " & Test)
    Text1.Text = Test
    End Sub


    The output of text1.text was "3628" lol

  12. #12
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Command Prompt

    You could read the textfile you have written into a textbox.

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Command Prompt

    Read the outputted file into your program using basic file i/o and set the .Text property of your textbox to the
    contents (assuming mult-line textbox).
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14

    Thread Starter
    Banned ThaRubby's Avatar
    Join Date
    Apr 2005
    Location
    127.0.0.1
    Posts
    356

    Re: Command Prompt

    kk ill start googleing how to read files... thanks guys been a big help

  15. #15
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Command Prompt

    Quote Originally Posted by RobDog888
    At the end of my post I added a Note that you can get the CMD.exe location dynamically using the GetSystemDirectory API.

    I dont like to rely on the environ variable since it can be changed or deleted by the user.
    Yes I know, but that requires that cmd.exe is in the system folder. Besides the ComSpec environment variable is safe to use, Win9x doesn't even work properly if you change that to an invalid command interpretor. And on an NT based system the ComSpec environment variable is a system variable which you need admin rights to change.

    Anyhow... I've attached a module that uses a different approach (and a tiny bit more advanced) to this. It contains a function called GetCommandOutput that will shell any command and return the output written to StdOut and StdErr as a string. You can then do whatever you want with that string, such as write it to a file, display it in a text box or whatever...

    One of the (optional) arguments to this function is called fOEMConvert which would convert the OEM characters use by a command line to the Ansi characters used by Windows. This is especially importent if your command line program will display international characters (like Å or ü for example) since they are different in Ansi compared to OEM.
    Attached Files Attached Files

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Command Prompt

    VB Code:
    1. Dim sTemp as string
    2. dim sTotalString as string
    3. Open "C:\Dir.txt" For Input As #1
    4.     Line Input #1, stemp
    5.     stotalstring = stotalstring & stemp
    6. Close #1
    7. Text1.text = stotalstring
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Command Prompt

    Or :

    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


    Has someone helped you? Then you can Rate their helpful post.

  18. #18
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Command Prompt

    LOL, manavo11, that is basically the same code I have in the module I uploaded. Not exactly the same but it uses the same APIs.

  19. #19
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Command Prompt

    So the meat of both examples is the CreatePipe API correct?

    This is a great friendly thread. No flaming or attitude and lots of expertise.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  20. #20

    Thread Starter
    Banned ThaRubby's Avatar
    Join Date
    Apr 2005
    Location
    127.0.0.1
    Posts
    356

    Re: Command Prompt

    Ok thats awesome but one problem...

    Open "C:\out.txt" For Input As #1


    That only opens the very first line is there a way to change it to read multiple lines?

  21. #21
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Command Prompt

    Sorry, didn't see it, I was testing it before replying and you replied while I was testing.. Bah, whatever, you know what I mean


    Has someone helped you? Then you can Rate their helpful post.

  22. #22
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Command Prompt

    Quote Originally Posted by RobDog888
    This is a great friendly thread. No flaming or attitude and lots of expertise.
    Aren't we always friendly?

  23. #23
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Command Prompt

    Oops, sorry we need a do while loop.
    VB Code:
    1. Dim sTemp as string
    2. dim sTotalString as string
    3. Open "C:\Dir.txt" For Input As #1
    4.     do while EOF(1) = False
    5.         Line Input #1, stemp
    6.         stotalstring = stotalstring & stemp
    7.     Loop
    8. Close #1
    9. Text1.text = stotalstring
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  24. #24
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Command Prompt

    Rob forgot the loop *Slap*

    VB Code:
    1. Open "C:\Dir.txt" For Input As #1
    2.     Do While Not EOF(1)
    3.         Line Input #1, stemp
    4.         stotalstring = stotalstring & stemp
    5.     Loop
    6. Close #1

    Or you can load the whole file without the loop :

    VB Code:
    1. Open "C:\Dir.txt" For Input As #1
    2.         stotalstring = Input(LOF(FF), FF)
    3. Close #1
    Last edited by manavo11; May 3rd, 2005 at 06:44 PM.


    Has someone helped you? Then you can Rate their helpful post.

  25. #25

    Thread Starter
    Banned ThaRubby's Avatar
    Join Date
    Apr 2005
    Location
    127.0.0.1
    Posts
    356

    Re: Command Prompt

    Yea thanks got it sorry i asked i figured that part on my own stupid question -.- Oh and this thread was like instant messageing we all must be really bored

  26. #26
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Command Prompt

    Quote Originally Posted by manavo11
    Rob forgot the loop *Slap*
    I fixed it before you replied so no SLAPPING

    Quote Originally Posted by JA
    Aren't we always friendly?
    Yes, always friendly.

    Just imaging ThaRubby, all this attention and great code just for the asking.
    I highly doubt any other forum is like ours
    Its like this almost ALL the time.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  27. #27
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Command Prompt

    Quote Originally Posted by RobDog888
    So the meat of both examples is the CreatePipe API correct?
    Yes, the main difference between my and manavo11's code is that my also use the DuplicateHandle API function so that it can (optionally) read from both StdOut as well as StdErr. My code also is in a function that returns the string instead of writing it directly to a textbox. But basically it's the same idea.

  28. #28
    Fanatic Member
    Join Date
    Sep 2002
    Location
    Lexington, SC
    Posts
    586

    Re: Command Prompt

    Does your code have the same problem of freezing or crashing under 95, and 98 systems Joacim?

    And on another curious note how hard would it be to port code like that over to VB .NET, I'm trying to learn .Net and migrate over to it, but I could see code like this being handy in some situations.

  29. #29
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Command Prompt

    In .NET you can write a "Console Application" for this type of use.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  30. #30
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Command Prompt

    Quote Originally Posted by StevenHickerson
    Does your code have the same problem of freezing or crashing under 95, and 98 systems Joacim?
    The code I showed works fine on Win9x. If it freezes it must be because of other code you're using

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