Guide to the Command Line Interface (CLI)

Command Line Interfaces (CLIs) are essential tools for interacting with software applications in server environments. They allow users to execute programs, manage configurations, and automate tasks through simple text commands. Appligent Document Solutions leverages the CLI in all its server-based applications, making them versatile for integration into various workflows using any programming language or scripting environment. This documentation provides a guide on executing applications using a CLI, focusing on common shell environments and how to retrieve results from such executions.

Command line interfaces provide a robust way to interact with server-based applications, offering flexibility and integration capabilities across various systems. By understanding how to execute and utilize these applications from the command line, users can effectively incorporate Appligent solutions into their workflows, enhancing productivity and automation.

Common Shell Environments

Before executing CLI commands, it's important to understand the shell environment you are working in. Here are the most common shell environments:

  1. Bash (Bourne Again SHell) - The most common shell on Linux and macOS systems. It provides extensive scripting capabilities and is the default shell on many Unix-like systems.
  2. CMD (Command Prompt) - A command line interpreter on Windows operating systems. It supports a set of specific commands and differs in syntax and capabilities from Bash.
  3. PowerShell - A more powerful command line scripting environment than CMD, available on Windows systems. It is designed for system administration and automation.

Executing Applications via CLI

To execute an Appligent server-based application via the command line:

  1. Open your command line interface:
    • On Windows, search for CMD or PowerShell in the start menu.
    • On macOS or Linux, open the Terminal application.
  2. Navigate to the application directory:

    Use the cd command to change the directory to where the Appligent application is located. For example:

    cd /path/to/appligent/application
  3. Execute the application:

    Run the application by typing its name followed by any required arguments or parameters. For instance:

    ./appligentApp --option1 value1 --option2 value2

    Replace appligentApp with the actual application name and adjust the options as necessary.

Getting Results from the Application

When you execute an application via CLI, the output can be displayed directly in the console, written to a file, or both, depending on the application's design.

  • Direct Output: After execution, the output may appear directly in your terminal. This is immediate and useful for quick checks or when continuous feedback is needed.
  • Writing to a File: For more permanent storage or when dealing with large amounts of data, outputs can be redirected to a file using logging operators. For example: ./appligentApp -l output.txt
    This command directs the output of appligentApp to a file named output.txt.

Advanced Integration

Appligent applications can be integrated into automated workflows using scripting or programming languages. They also support "Watched Folders" or "Watched Directories," where the application monitors a folder and automatically processes files placed in it.

Example of Script Integration:

Here's an example using Bash script to automate an Appligent application:

#!/bin/bash
# A script to automate Appligent application processing

# Define the input and output directory
inputDir="/path/to/input"
outputDir="/path/to

# Loop through all files in the input directory
for file in $inputDir/*
do
  # Execute the application for each file
  ./appligentApp -o "$outputDir/$(basename $file)" "$file"
  echo "Processed: $file" done

Common Command Line Commands in Linux and Windows

Function Linux Command Windows Command
Change Directory cd /path/to/directory cd \path\to\directory
List Directory Contents ls dir
Copy Files cp source destination copy source destination
Move/Rename Files mv source destination move source destination
Delete Files rm file del file
Display File Content cat file type file
Find Files find / -name filename dir filename /s
Display Current Directory pwd cd
Clear Screen clear cls

Handling CLI Commands in Different Programming Languages

C++

C++ uses the system() function from <cstdlib> to execute command line commands. The function returns the status code of the command executed. If the command fails, it returns a non-zero value.

#include <iostream>
#include <cstdlib>

int main() {
    // Replace 'your_command' with your CLI command
    int status = system("your_command");
    
    if (status != 0) {
        std::cerr << "Error executing command." << std::endl;
        return 1;
    }

    std::cout << "Command executed successfully." << std::endl;
    return 0;
}

Java

Java can execute command line commands using the ProcessBuilder class. This class provides methods to manage input, output, and error streams, and to check the exit status of the command.

import java.io.*;

public class ExecuteShellCommand {
    public static void main(String[] args) {
        ProcessBuilder processBuilder = new ProcessBuilder();
        // Replace 'your_command' with your CLI command
        processBuilder.command("bash", "-c", "your_command");

        try {
            Process process = processBuilder.start();

            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }

            int exitVal = process.waitFor();
            if (exitVal == 0) {
                System.out.println("Command executed successfully.");
            } else {
                System.out.println("Error");
            }

        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}

Visual Basic (VB.NET)

In VB.NET, the Process class is used to execute commands. It allows the redirection of input, output, and error streams, and can wait for the command to complete to check the exit status.

Imports System.Diagnostics

Module Module1
    Sub Main()
        Dim process As New Process()
        process.StartInfo.FileName = "cmd.exe"
        process.StartInfo.Arguments = "/c your_command" ' Replace 'your_command' with your CLI command
        process.StartInfo.UseShellExecute = False
        process.StartInfo.RedirectStandardOutput = True
        process.StartInfo.RedirectStandardError = True
        process.Start()

        Dim output As String = process.StandardOutput.ReadToEnd()
        Dim errors As String = process.StandardError.ReadToEnd()

        process.WaitForExit()

        If process.ExitCode = 0 Then
            Console.WriteLine("Command executed successfully.")
            Console.WriteLine(output)
        Else
            Console.WriteLine("Error executing command.")
            Console.WriteLine(errors)
        End If
    End Sub
End Module

Python

Python's subprocess module provides a powerful interface for spawning new processes, connecting to their input/output/error pipes, and obtaining their return codes. This example demonstrates basic usage.

import subprocess

# Replace 'your_command' with your CLI command
process = subprocess.run(["your_command"], text=True, capture_output=True, shell=True)

if process.returncode == 0:
    print("Command executed successfully.")
    print(process.stdout)
else:
    print("Error executing command.")
    print(process.stderr)