1. How do I run another program?
Use the Exec function - this allows you to specify the command line arguments, also it allows you to control whether your program waits for the other
program to finish, or whether your program continues running immediately after calling Exec. For example:
// TestExec.cls
Ubercode 1 class TestExec
public function main()
code
call Exec("notepad.exe", "", EXEC_NOWAIT+SW_SHOWNORMAL)
end function
end class
The example just shown uses Exec to open the Windows notepad.exe program. The EXEC_NOWAIT option specifies the program continues running immediately
after starting notepad, and the SW_SHOWNORMAL option specifies that notepad is shown in a normal sized window (ie not minimized and not maximized).
2. How do I pass a command line argument to another program?
Again the Exec function is able to do this. Refer to the example above, where the second string argument of Exec is an empty string. This
parameter can be replaced by a command line argument which is passed to notepad on the command line. Notepad interprets this argument as the name of the file
to open. Thus the following code:
call Exec("notepad.exe", "myfile.txt", EXEC_NOWAIT+SW_SHOWNORMAL)
uses notepad to open the file myfile.txt (assuming this file exists). If you are running another Ubercode program, you can obtain the command line
arguments as a string in parameter of function main(), or by using the Arguments constant.
3. How do I get the task list (list of running programs)?
Use the Applications function with a For each loop to build up the list of programs. You can then search the resulting list or display the
list to the user. The following example displays the programs in a list:
// Apps.cls
Ubercode 1 class Apps
public function main()
var
app:string[*]
applist:string[*]
code
for each app in Applications()
applist <- applist + app + NL
end for
call Listbox("Apps", "", applist)
end function
end class
This works as follows: The for each loop gets each application name returned by the Applications function, and appends it to a string. The
string is then shown to the user in a Listbox window. After the user clicks OK the program will end.
4. How do I run an MS-DOS program?
Use the Exec function to run a command shell (command.com or cmd.exe). The command shell can then run inbuilt MS-DOS commands such as Dir,
Copy etc. For example:
// Msdos.cls
Ubercode 1 class Msdos
public function main()
code
call Exec("cmd.exe", "/c dir", EXEC_WAIT+SW_SHOWNORMAL)
end function
end class
The example just shown uses Exec to run the Windows command shell (cmd.exe under Windows NT / 2000 / XP and command.com under earlier versions of
Windows). The command shell runs the Dir command and then quits, then the call to Exec returns and the program ends. Note the EXEC_WAIT option
waits for cmd.exe to quit, which it does immediately after the directory listing has been shown.
5. How do I run code in other languages (C, C++, Delphi etc)?
The easiest way of doing this is to compile the external code into a DLL. Declare public functions in the DLL for the code you want to run, being sure to
use the STDCALL convention. You will then be able to call these functions up from Ubercode programs.
|