Search code examples
operating-systemballerina

How can I call OS commands from within ballerina


I want to generate some certificates, using openSSL and provide them via REST.

I can not find a way to call my openssl in linux to generate the certificate and use it in ballerina.

no plugin found

Or is there another way to generate certificates in ballerina. There is some support for KeyStores in ballerina/crypto module https://ballerina.io/learn/api-docs/ballerina/crypto.html#KeyStore


Solution

  • This will available with ballerina-1.0.0 distribution through the ballerina/system module. The API will be look like this.

    # Executes an operating system command as a subprocess of the current process.
    #
    # + command - The name of the command to be executed
    # + env - Environment variables to be set to the process
    # + dir - The current working directory to be set to the process
    # + args - Command arguments to be passed in
    # + return - Returns a `Process` object in success, or an `Error` if a failure occurs
    public function exec(@untainted string command, @untainted map<string> env = {}, 
                         @untainted string? dir = (), @untainted string... args) 
                         returns Process|Error = external;