-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d016eca
commit 5004a26
Showing
2 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters