Author Topic: Customisable DOS console  (Read 2273 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Customisable DOS console
« on: April 02, 2013, 04:45:25 AM »
You can access all the DOS commands and add some of your own :)

Code: [Select]
  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

Haim

  • Guest
Re: Customisable DOS console
« Reply #1 on: April 03, 2013, 08:04:41 PM »
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

Charles Pegge

  • Guest
Re: Customisable DOS console
« Reply #2 on: April 03, 2013, 08:15:45 PM »
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

Haim

  • Guest
Re: Customisable DOS console
« Reply #3 on: April 03, 2013, 08:40:27 PM »
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