Skip to main content
Version: Torizon OS 6.x.y

Pass Arguments to Applications

Introduction

This article describes how to pass arguments to applications that run inside containers.

Depending on the development phase of your project, the process of sending arguments to applications varies. When debugging, you have to edit the configuration files created by the Torizon IDE extension. Otherwise, after building an image, arguments are passed through Dockerfile intructions and Docker Run commands.

This article complies with the Typographic Conventions for Torizon Documentation.

Prerequisites

Debugging

When debugging, the Torizon IDE extension manages the creation and running of the debugger container. Also, to facilitate project management, the extension provides various configuration files. Among them, the launch.json file stores the configurations required to launch the application with the debugger.

To pass command-line arguments to your application, edit the launch.json file:

  1. Locate the .vscode folder in your project repository.
  2. Inside the .vscode folder, find and open the launch.json file.
  3. Search for the configuration name associated with the architecture of your target device:
    1. TorizonV7 for ARM32 devices.
    2. TorizonV8 for ARM64 devices.
  4. Modify the args variable by adding your program's arguments. Note that each argument is separated with commas. For example: "args": ["0","5"].

As an example, the video below demonstrates these steps for a .NET Core sample:

Runtime

There are multiple methods available for passing command-line arguments to containers. Therefore, we recommend referring to the Dockerfile Reference documentation.

As an example, the steps to pass arguments to a .NET Core sample are as follows:

  1. In your project repository, locate and open the Dockerfile.
  2. Add the ENTRYPOINT instruction to configure the container to run as an executable. This is achieved by defining the application as the entry point of the container:
ENTRYPOINT ["gpioDotnet"]
  1. Add the CMD instruction to the Dockerfile. This command defines default arguments for the container entry point:
CMD ["0","5"]

When running the container, we can still overwrite default ENTRYPOINT arguments. The arguments are passed after the container name in the Docker Run command, as shown below:

# docker run --rm -it --device /dev/gpiochip0 <container_name> <arg_1> <arg_2>


Send Feedback!