decthings

Spawned / spawnCommand


Spawn a command which is running in an empty filesystem.

Request parameters

{
    /** Which launcher to use for running the command. */
    executionLocation: {
        type: 'persistentLauncher',
        persistentLauncherId: string
    } | {
        type: 'temporaryLauncher',
        spec: LauncherSpec
    },
    /** Name of the command to run, without any arguments. */
    command: string,
    /** Arguments to pass to the command */
    args: string[],
    options?: {
        /** Will automatically terminate the command after this amount of time. Default: 3600. */
        timeoutSeconds?: number,
        /**
         * Will automatically terminate the command if no output is received from the process for this amount of time.
         * Default: 600.
         */
        timeoutAfterInactiveSeconds?: number
    },
    /**
     * If true, immediately subscribes you to events "stdout", "stderr" and "exit" for the spawned command. Default:
     * true.
     */
    subscribeToEvents?: boolean
}

Response

{
    /** If successful. One of "result" and "error" will be present. */
    result?: {
        /** A unique identifier which you should use in subsequent API calls. */
        spawnedCommandId: string
    },

    /** If failed */
    error?: {
        code: 'persistent_launcher_not_found' | 'quota_exceeded' | 'server_overloaded' | 'bad_credentials' | 'too_many_requests' | 'payment_required' | 'unknown'
    } | {
        code: 'invalid_parameter',
        parameterName: string,
        reason: string
    }
}

Example

Following the installation guide to setup the Decthings API for TypeScript. Add your parameters to the following code and run it in Node.js, or in a browser by using a bundler.

The code reads your API key from file. Create an API key and save it to the file "auth.txt". Keep your key safe!

import * as fs from 'fs'
import { DecthingsClient } from '@decthings/api-client'

let apiKey = fs.readFileSync('./auth.txt').toString().trim()
let client = new DecthingsClient({ apiKey })

async function main() {
    try {
        let response = await client.spawned.spawnCommand({
            executionLocation: /* Add executionLocation here */,
            command: /* Add command here */,
            args: /* Add args here */
        })
        if (result.error) {
            // Decthings sent us an error
            console.log(response.error)
        } else {
            // Success!
            console.log(response.result)
        }
    }
    catch (e) {
        // Client throws an error on connection issues. The function may or may not have succeded
        console.log(e)
    }
}
main()

Product

  • Documentation
  • Pricing
  • API reference
  • Guides

Company

  • Support

Get going!

Sign up
  • Terms and conditions
  • Privacy policy
  • Cookie policy
  • GitHub
  • LinkedIn

This website uses cookies to enhance the experience.

Learn more