RE: NONMEM priority on windows NT/2000
From: "Sale, Mark" <ms93267@GlaxoWellcome.com>
Subject: RE: NONMEM priority on windows NT/2000
Date: Tue, 8 May 2001 08:39:23 -0400
Nick, Bill, Joern and other nmusers
Could be done, maybe I'll do that tonight. In the meantime, below is last night work, vb (version 6.0) code to run NONMEM. I can't send the executable from GSK (virus protection), but I could send it from a yahoo account it you want it. The executable (low_nm) is placed in c:\nmv\util (or anywhere in the path), then edit the three lines in nmfe5.bat
nonmem.exe
copy output %2
del output
To remark out these and insert low_nm %2
REM nonmem.exe
REM copy output %2
REM del output
low_nm %2
This starts a new DOS window, but returns control to the existing command line (which I think is nice, I don't have to keep opening new DOS windows). The intermediate output appears in the new window, which closes when done and a message box appears telling you that NONMEM is done and in which directory.
Let me know if you want the executable (I promise no viruses)
Mark
Code for low_nm VB6 module
to implement, start a new project, add this as a module and set the start up subroutine to be main. In VB6 you don't need to add any form, (you can delete the one you get by default)
______________________________________________________________________
Private Const wait = 100 ' msec wait for waitforsingle object
Private Const CREATE_NEW_CONSOLE = &H10
Private Const NORMAL_PRIORITY_CLASS = &H20
Private Const IDLE_PRIORITY_CLASS = &H40
Private Const HIGH_PRIORITY_CLASS = &H80
Private Const REALTIME_PRIORITY_CLASS = &H100
Private Const CREATE_NEW_PROCESS_GROUP = &H200
Private Const CREATE_NO_WINDOW = &H8000000
Private Const USESHOWWINDOW = 1
Private Const SW_HIDE = 0
Private Const SW_SHOWNORMAL = 1
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_SHOWMAXIMIZED = 3
Private Const SW_SHOWNOACTIVATE = 4
Private Const SW_SHOW = 5
Private Const SW_MINIMIZE = 6
Private Const SW_SHOWMINNOACTIVE = 7
Private Const SW_SHOWNA = 8
Private Const SW_RESTORE = 9
Private Const SW_SHOWDEFAULT = 10
' the process information for createprocess
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
'
'The STARTUPINFO structure allows the CreateProcess function to control many aspects of the creation process. This structure is described in Appendix B.
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
' used to run nonmem
Private Declare Function CreateProcessBynum Lib "kernel32" Alias
"CreateProcessA" _
(ByVal lpApplicationName As String, ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment
As Any, _
ByVal lpCurrentDirectory As String, lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long
' used in loop to see when it is done
Private Declare Function WaitForSingleObject& Lib "kernel32" (ByVal hHandle
As Long, _
ByVal dwMilliseconds As Long)
' used to clean up memory when done
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long)
As Long
Sub Main()
Dim res As Long ' just a return value
Dim rval As Long ' also a return value
Dim proc_hand As Long ' handle to nonmem process
Dim nm_dir As String, output_file As String
On Error GoTo call_nm_error ' basic error handler
nm_dir = CurDir ' to make sure we end up in the same directory as we started
Dim sinfo As STARTUPINFO, pinfo As PROCESS_INFORMATION
sinfo.cb = Len(sinfo)
sinfo.lpReserved = vbNullString
sinfo.lpDesktop = vbNullString
sinfo.lpTitle = "NONMEM run window"
sinfo.dwFlags = USESHOWWINDOW
' sinfo.wShowWindow = SW_HIDE
sinfo.wShowWindow = SW_SHOWNORMAL
' run nonmem
res = CreateProcessBynum("nonmem.exe", vbNullString, 0, 0, _
True, IDLE_PRIORITY_CLASS, ByVal 0&, vbNullString, _
sinfo, pinfo)
' get the process handle
proc_hand = pinfo.hProcess
rval = 200 ' = 258 IF PROCESS STILL RUNNING
While rval > 1
' see if it is done yet
rval = WaitForSingleObject(proc_hand, wait)
Wend 'need new process, set missing_proc 258 is still running
' clean up memory
Call CloseHandle(pinfo.hProcess)
Call CloseHandle(pinfo.hThread)
' output file is command line argument
output_file = Command()
' copy to user specified output file %2 in nmfe5.bat
FileCopy "output", output_file
If Dir(nm_dir & "\output") <> "" Then ' check to see if "output" is present
Kill "output" ' if so, delete it
End If
ChDir nm_dir ' change back to original directory
MsgBox "Done with NONMEM in " & nm_dir
End
call_nm_error: ' basic error handeling, actually doesn't do anything.
MsgBox "Error in Call_nm"
On Error GoTo 0
End Sub