Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Add examples for running code in execution environments

...

To run raw code on Charity Engine, just upload your code and specify the relevant execution environment, either using a "named" environment in our App Library, or by specifying an appropriate container on Docker Hub or the web (see 1.2 "Applications", above)

Examples:

A simple example in python would be to run a "hello world" command:

Code Block
languagetext
titlehello-world.py
print("hello world")

Upload and execute this file in Python by using the Remote CLI:

Code Block
languagebash
ce-cli --app "docker:python:slim" --commandline "python /local/input/hello-world.py > /local/output/hello.out" --inputfile hello-world.py --auth [...]

This produces an output file in the local directory named hello.out that contains the text string "hello world".

An example in NodeJS could perform a simple sum of all numbers passed as parameters. Consider a script named calc-sum.js:

Code Block
languagetext
titlecalc-sum.js
const fs = require('node:fs');

var sum = 0;
for (let i = 2; i < process.argv.length; i++) {
  sum += Number(process.argv[i]);
}
try {
  fs.writeFileSync('/local/output/sum.out', sum.toString());
}
catch (e) {
  console.log(e);
}

Because the node Docker container does not handle I/O redirects in the same way as the python container, the script handles writing the output to the correct location within the container and the Remote CLI --commandline only specifies the script and the numbers to include in the sum:

Code Block
languagebash
ce-cli --app "docker:node:slim" --commandline "node /local/input/calc-sum.js 1 2 3 4.2" --inputfile calc-sum.js --auth [...]

This produces an output file named "sum.out" in the local directory, which contains the sum of the numbers given on the command line.sfsdfd

See instructions on the appropriate interface (section 1.1) for further execution details.

...

Textstyles
Colorrgb(236,0,140)

[In development]

 

Support

Please contact us with any questions.

...