Problem getting exit code returned by DOS command

P

pkirow

Hi folks,

When I try to invoke MS-DOS programm from VB, the exit code return is aways
0.
My code is:

Option Explicit

Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
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 WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess
As Long, _
ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long


Public Function ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim procId As Long

start.cb = Len(start)

procId = Shell(cmdline$, vbNormalFocus)


proc.hProcess = OpenProcess(ACCESS_TYPE, False, procId)

Call WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, procId)

ExecCmd = procId
End Function

Private Sub CommandButton1_Click()
Dim retval As Long
retval = ExecCmd("java -jar Test.jar abc")
MsgBox "Process Finished, Exit Code " & retval
End Sub

When I run this command (java -jar Test.jar abc) the exit codes are between
3 and -6.

Any help and/or ideas?

Plamen.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top