Tai-San
asked on
returning the result of a dos application when finished
hi i use this code to get the result of a dos application but the problem with this is that i cant get all the text back, only the amout that can be cept in a long is returned and i cant seem to make it work as either single or double.
Option Explicit
Private Declare Function CreatePipe Lib "kernel32" ( _
phReadPipe As Long, _
phWritePipe As Long, _
lpPipeAttributes As Any, _
ByVal nSize As Long) As Long
Private Declare Function ReadFile Lib "kernel32" ( _
ByVal hFile As Long, _
ByVal lpBuffer As Long, _
ByVal nNumberOfBytesToRead As Long, _
lpNumberOfBytesRead As Long, _
ByVal lpOverlapped As Any) As Long
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, _
lpProcessAttributes As Any, lpThreadAttributes As Any, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As Any, lpProcessInformation As Any) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const STARTF_USESTDHANDLES = &H100&
Private Sub ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION, ret As Long, bSuccess As Long
Dim start As STARTUPINFO
Dim sa As SECURITY_ATTRIBUTES, hReadPipe As Long, hWritePipe _
As Long
Dim bytesread As Long, mybuff As String
Dim i As Integer
mybuff = String(256, Chr$(65))
sa.nLength = Len(sa)
sa.bInheritHandle = 1&
sa.lpSecurityDescriptor = 0&
ret = CreatePipe(hReadPipe, hWritePipe, sa, 0)
If ret = 0 Then
MsgBox "CreatePipe failed. Error: " & Err.LastDllError
Exit Sub
End If
start.cb = Len(start)
start.dwFlags = STARTF_USESTDHANDLES
start.hStdOutput = hWritePipe
' Start the shelled application:
ret& = CreateProcessA(0&, cmdline$, sa, sa, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
If ret <> 1 Then
MsgBox "CreateProcess failed. Error: " & Err.LastDllError
End If
bSuccess = ReadFile(hReadPipe, mybuff, 100000, bytesread, 0&)
If bSuccess = 1 Then
Text1.Text = Left(mybuff, bytesread)
Else
MsgBox "ReadFile failed. Error: " & Err.LastDllError
End If
ret& = CloseHandle(proc.hProcess)
ret& = CloseHandle(proc.hThread)
ret& = CloseHandle(hReadPipe)
ret& = CloseHandle(hWritePipe)
End Sub
Option Explicit
Private Declare Function CreatePipe Lib "kernel32" ( _
phReadPipe As Long, _
phWritePipe As Long, _
lpPipeAttributes As Any, _
ByVal nSize As Long) As Long
Private Declare Function ReadFile Lib "kernel32" ( _
ByVal hFile As Long, _
ByVal lpBuffer As Long, _
ByVal nNumberOfBytesToRead As Long, _
lpNumberOfBytesRead As Long, _
ByVal lpOverlapped As Any) As Long
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, _
lpProcessAttributes As Any, lpThreadAttributes As Any, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As Any, lpProcessInformation As Any) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const STARTF_USESTDHANDLES = &H100&
Private Sub ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION, ret As Long, bSuccess As Long
Dim start As STARTUPINFO
Dim sa As SECURITY_ATTRIBUTES, hReadPipe As Long, hWritePipe _
As Long
Dim bytesread As Long, mybuff As String
Dim i As Integer
mybuff = String(256, Chr$(65))
sa.nLength = Len(sa)
sa.bInheritHandle = 1&
sa.lpSecurityDescriptor = 0&
ret = CreatePipe(hReadPipe, hWritePipe, sa, 0)
If ret = 0 Then
MsgBox "CreatePipe failed. Error: " & Err.LastDllError
Exit Sub
End If
start.cb = Len(start)
start.dwFlags = STARTF_USESTDHANDLES
start.hStdOutput = hWritePipe
' Start the shelled application:
ret& = CreateProcessA(0&, cmdline$, sa, sa, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
If ret <> 1 Then
MsgBox "CreateProcess failed. Error: " & Err.LastDllError
End If
bSuccess = ReadFile(hReadPipe, mybuff, 100000, bytesread, 0&)
If bSuccess = 1 Then
Text1.Text = Left(mybuff, bytesread)
Else
MsgBox "ReadFile failed. Error: " & Err.LastDllError
End If
ret& = CloseHandle(proc.hProcess)
ret& = CloseHandle(proc.hThread)
ret& = CloseHandle(hReadPipe)
ret& = CloseHandle(hWritePipe)
End Sub
Why don't you send the result to a text file and then have VB read that?
Leon
Leon
ASKER
would that do any difference?
Sure, the problem you are having is passing a memory space reference from DOS to VB. By dealing with a text file you avoid the entire situation all together. You can start you app in VB do the the shell command to launch your DOS what ever, then when it is done access the text file, get the required info and delete the file. Much cleaner and less code, I bet.
Leon
Leon
ASKER
could you give an example?
What is the output of your DOS application?
ASKER
its:
Mo'PaQ 2000 build 2210 Copyright (c) 2000 Justin Olbrantz(Quantam)
The official client of the MPQ API Library v2.00 by Andrey Lelikov and Quantam
For the most recent version, go to www.campaigncreations.com/starcraft/mpq2k/
Usage:
Add files: mpq2k a <archive> <*src_file> [int_name] [/c] [/wav] [/r] [/new]
Extract files: mpq2k e <archive> <*int_file> [target_dir] [/fp] [/r]
Rename files: mpq2k r <archive> <int_file> <new_name>
Move files: mpq2k m <archive> <*src_file> <target_dir> [/r]
Delete files: mpq2k d <archive> <*int_file> [/r]
Flush archive: mpq2k f <archive>
List files: mpq2k l <archive> [filter] [out_file] [/lf] [/p]
Run scripts: mpq2k s <script>
Command help: mpq2k h <command>
Mo'PaQ 2000 build 2210 Copyright (c) 2000 Justin Olbrantz(Quantam)
The official client of the MPQ API Library v2.00 by Andrey Lelikov and Quantam
For the most recent version, go to www.campaigncreations.com/starcraft/mpq2k/
Usage:
Add files: mpq2k a <archive> <*src_file> [int_name] [/c] [/wav] [/r] [/new]
Extract files: mpq2k e <archive> <*int_file> [target_dir] [/fp] [/r]
Rename files: mpq2k r <archive> <int_file> <new_name>
Move files: mpq2k m <archive> <*src_file> <target_dir> [/r]
Delete files: mpq2k d <archive> <*int_file> [/r]
Flush archive: mpq2k f <archive>
List files: mpq2k l <archive> [filter] [out_file] [/lf] [/p]
Run scripts: mpq2k s <script>
Command help: mpq2k h <command>
ASKER
dont follow the link
the output of the dos program is excactly as said above including the link (though its not a link in dos)
the output of the dos program is excactly as said above including the link (though its not a link in dos)
Oh, ok. Sorry, can you have the DOS program output this to a file?
Leon
Leon
ASKER
its not my program, i dont have the source. i am creating a GUI for it but i cant get my code to return enough of the text
I see, does the output normally go the command prompt?
Leon
Leon
ASKER
yes it does
ASKER
could you create an example out of this cause im having many problems with it
Ok, but you will have to wait till tomorrow, since I am on my way home.
Leon
Leon
ASKER
okey
BTW are you only getting 256 characters? You only dimension mybuff to 256 characters.
ASKER
i solved that one but i found another problem, the program says that it cant get access to listfile.dat
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i got it to work this far so that the program works with that code ms provided but im having trouple with the batch file
i use this code in the batch file:
mpq2k.exe > c:\LIST.DAT
but it just wont write more than the first lines, then comes a double new line and it doesnt write any further
i use this code in the batch file:
mpq2k.exe > c:\LIST.DAT
but it just wont write more than the first lines, then comes a double new line and it doesnt write any further
ASKER
i guess ive got what i need to do now:
1: copy my application to a specific path so i can specify all of it
2: make specific batch file
3: delete all, now, unnecesarry files and copy whats been changed
ill return
1: copy my application to a specific path so i can specify all of it
2: make specific batch file
3: delete all, now, unnecesarry files and copy whats been changed
ill return
ASKER
ByVal lpBuffer As Long. _
was supposted to be:
ByVal lpBuffer As String