Please enable JavaScript to view this site.

thinBasic Help Manual

* * HELP & MANUAL PREMIUM PACK 4 DEMO VERSION * *

This documentation was styled with a demo skin from the Premium Pack 4 add-on for Help & Manual. The contents of the skin are encrypted and not configurable. You can only publish HM projects with this skin. You cannot edit it or change it.

This version is copyright and may only be used for local testing purposes. It may not be distributed.

Please purchase the full version of the Premium Pack to get the configurable skins and remove this notice. The package will also include the Toolbox configuration utility for Premium Pack skins.

 

Description

 

Execute a command and capture command output if any.

 

Syntax

 

sOutput = Shell_CaptureOutput(sCmdLine, sStartDirectory, lShow, dwMillisecondsWait)

 

Returns

 

String, the output of the called process.

 

Parameters

 

Name

Type

Optional

Meaning

sCmdLine

String

No

The command line to be executed

 

The maximum length of command line string is 32,768 characters.

 

To execute operating system commands use:

"cmd /c " followed by the command.

 

sStartDirectory

String

No

The full path to the current directory for the process. The string can also specify a UNC path.

 

If this parameter is NULL, the new process will have the same current drive and directory as the calling process. (This feature is provided primarily for shells that need to start an application and specify its initial drive and working directory.)

lShow

Number

No

Controls how the window is to be shown. Possible values:

%SW_HIDE

%SW_SHOWNORMAL

%SW_SHOWDEFAULT

dwMillisecondsWait

Number

No

It indicates the maximum number of milliseconds the command will wait till return

 

Remarks

 

The new process runs in the security context of the calling process.

Additional info: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa

 

Restrictions

 

By default Shell is a synchronous function.

 

See also

 

OS_Shell

OS_ShellExecute

 

Examples

 

'---Execute an operating system command and capture its output

uses "console"

 

string sCommand

 

'---Loop until command is an empty String

Do

  sCommand = sGetCommand 

 

  if len(sCommand) > 0 Then

    printl shell_captureoutput("cmd /c " & sCommand, "c:\"%SW_hide, 10000)

  Else

    exit do

  end If

Loop

 

printl "---Press a ley to end ---"

WaitKey

 

function sGetCommand() as String

  local sCommand as String

  

  print "Type an operating system command: " in %CCOLOR_FYELLOW

  sCommand = Console_ReadLine

 

  '---Check some allowed commands

  select case ucase$(parse$(sCommand, any " (" & $TAB & $DQ, 1))

    Case "DIR"

    case "HELP"

    CASE "VER"

    CASE "TITLE"

    case ""

    case Else

      sCommand = "VER"

      printl "Command not supported" in %CCOLOR_FLIGHTRED

  end Select

  

  function = sCommand

  

end function

Created with Help+Manual 8 and styled with Premium Pack Version 4 © by EC Software