Oxygen Basic
Programming => Example Code => General => Topic started by: Charles Pegge on April 02, 2013, 04:45:25 AM
-
You can access all the DOS commands and add some of your own :)
includepath "$/inc/"
'$filename "t.exe"
'include "rtl32.inc"
include "MinWin.inc"
extern lib "KERNEL32.DLL"
! AttachConsole alias "AttachConsole" (sys pp) as sys
! AllocConsole alias "AllocConsole" () as sys
! FreeConsole alias "FreeConsole" () as sys
! SetConsoleMode alias "SetConsoleMode" (sys h,m)
! GetCommandLine alias "GetCommandLineA" () as char*
! GetStdHandle alias "GetStdHandle" (sys handle) as sys
! WriteConsole alias "WriteConsoleA" (sys hConsoleOutput, lpBuffer, nNumberOfCharsToWrite, *lpNumberOfCharsWritten, lpReserved) as sys
! ReadConsole alias "ReadConsoleA" (sys hConsoleInput,lpBuffer,nNumberOfCharsToRead, *lpNumberOfCharsRead, *pInputControl) as sys
! SetConsoleTitle alias "SetConsoleTitleA" (char*lpConsoleTitle) as sys
! ShellExecute alias "ShellExecuteA" lib "Shell32.dll" _
(sys Hwnd, char* operation,file,parameters,directory,sys ShowCmd) as sys
end extern
%STD_INPUT_HANDLE = -10
%STD_OUTPUT_HANDLE = -11
%STD_ERROR_HANDLE = -12
function DOS(string s)
======================
string c
STARTUPINFO infs
PROCESS_INFORMATION infp
if s then c="cmd.exe /c" else c="cmd.exe"
CreateProcess null,c+" "+s,0,0,0,0,0,0,@infs,@infp
CloseHandle infp.hProcess
CloseHandle infp.hThread
end function
sys q,consIn,consOut,consErr
q=AllocConsole
'q=AttachConsole -1
ConsIn =GetStdHandle (%STD_INPUT_HANDLE)
ConsOut=GetStdHandle (%STD_OUTPUT_HANDLE)
ConsErr=GetStdHandle (%STD_ERROR_HANDLE)
'
string bufin
long buflen,bufrit
string tab,cr,qu
'
tab=chr 9
qu=chr 34
cr=chr(13,10)
bufin=nuls 1000
SetConsoleTitle "OxygenBasic"
function output(bufout as zstring)
==================================
buflen=len bufout
WriteConsole ConsOut, strptr bufout,buflen,bufrit,0
end function
function input() as string
==========================
ReadConsole consin,strptr bufin,100,bufrit,0
function=left bufin,bufrit
end function
function outinput(s as zstring) as string
=========================================
if s then output s
ReadConsole consin,strptr bufin,100,bufrit,0
function=left bufin,bufrit
end function
function commandline() as string
================================
dim byref z as zstring
&z=GetCommandLine
function=z
end function
function Console(string ti)
===========================
zstring dt[256]
'GetCurrentDirectory 256, strptr dt
output ti cr cr
output GetCommandline() cr cr
do
string s=outinput(dt+chr(32,2,32))
le=len(s)-2
s=lcase left s,le
if s="exit" then exit do
if s then DOS s
end do
end function
Console "CUSOMISED CONSOLE"
FreeConsole
Charles
-
Hello,
could not run your code.
I am missing the definition of startupinfo. probably an old version of MinWin.inc
Where can I find the latest include files?
Haim
-
This release supports the includepath "$/inc/" exepath notation to find minwin. I think that is your problem here. Otherwise download the full Oxygen (in progress) from the downloads web page
http://www.oxygenbasic.org/forum/index.php?topic=654.msg5584#new
-
Hello,
Thanks for your response.
I downloaded the latest version, however, I still get the same error message about unrecognized StartupInfo instruction
I have no clue.
I'll keep looking for one ???
Thanks