Command Line Arguments

Prev Next

Introduction

Command line arguments are supplied to the B4P interpreter in addition to the B4P file name. The path and file name of the B4P program is actually considered as the first command line argument. Additional arguments can be provided in text form, such as further file names, names, locations, values, etc.

Following rules apply:

  • In contrast to command line switches and long options, the sequential order of these arguments is relevant.
  • The command line arguments must not start with 1 or more minus signs '-'.
  • The command line arguments do not influence the starting behavior of B4P.

Ways to provide command line arguments:

  • Windows: b4p Example.b4p Data1.txt Data2.txt
  • Linux / MacOS: ./Example.b4p Data1.txt Data2.txt

Accessibility to B4P Programs

The B4P program can access all command line arguments in the system variable command line arguments[n] which is an array.
Use the function member count() to check for the number of command line arguments provided, e.g. member count(command line arguments[]).

At least 1 command line argument is always available
n[] = member count( command line arguments[] );
echo( "Number of command line arguments: ", n[] );
for (a[]=0, a[]<n[], a[]++) echo("Argument ", a[], ": ", command line arguments[a[]] );
Result
Number of command line arguments: 1
Argument 0: Example_Program.b4p
Try it yourself: Open GUI_Features_Command_line_arguments.b4p in B4P_Examples.zip. Decompress before use.