Skip to content

Commit

Permalink
feat: shell script example
Browse files Browse the repository at this point in the history
  • Loading branch information
wrussell1999 committed Nov 6, 2024
1 parent d016eca commit 5004a26
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
71 changes: 71 additions & 0 deletions shell-execute-code.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
id: shell-execute-code
namespace: company.team

inputs:
- id: dataset_url
type: STRING
defaults: https://huggingface.co/datasets/kestra/datasets/raw/main/csv/orders.csv

tasks:
- id: download_dataset
type: io.kestra.plugin.core.http.Download
uri: "{{ inputs.dataset_url }}"

- id: c_code
type: io.kestra.plugin.scripts.shell.Commands
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
containerImage: gcc:latest
commands:
- gcc example.c
- ./a.out
inputFiles:
orders.csv: "{{ outputs.download_dataset.uri }}"
example.c: |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
FILE *file = fopen("orders.csv", "r");
if (!file) {
printf("Error opening file!\n");
return 1;
}
char line[1024];
double total_revenue = 0.0;
fgets(line, 1024, file);
while (fgets(line, 1024, file)) {
char *token = strtok(line, ",");
int i = 0;
double total = 0.0;
while (token) {
if (i == 6) {
total = atof(token);
total_revenue += total;
}
token = strtok(NULL, ",");
i++;
}
}
fclose(file);
printf("Total Revenue: $%.2f\n", total_revenue);
return 0;
}
extend:
title: Run C code inside of a Shell environment
description: This flow uses a Shell Command to run C code with an inputFile generated dynamically from a task upstream.
tags:
- CLI
- Inputs
- Software Engineering
- Outputs
ee: false
demo: true
meta_description: This flow executes Shell Shell
Commands to run C code.
2 changes: 1 addition & 1 deletion shell-scripts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ tasks:
- cut -d ',' -f 2 file.csv | head -n 6
extend:
title: Run Shell Scripts and Shell commands in a working directory using a
PROCESS runner
Process Task Runner
description: This flow sequentially executes Shell Scripts and Shell Commands in
the same working directory using a local `Process` Task Runner.
tags:
Expand Down

0 comments on commit 5004a26

Please sign in to comment.