Skip to content

Commit

Permalink
A new wrapper attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
poing committed Feb 13, 2024
1 parent ef75376 commit 6d15571
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
21 changes: 21 additions & 0 deletions gems/wrapperV7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// wrapperV7.js
// Require the secrets package and assign it to a variable
const secrets = require('../secrets.js/secrets.js');

// Function to execute the commands sent from Python
function executeCommands(input_data) {


// Split the input_data into individual commands
const commands = input_data.split(';');

// Execute each command
commands.forEach(command => {
eval(command); // Using eval to execute the command strings
});
}

console.log("Commands received from Python:", process.argv[2]));

// Execute the commands sent from Python
executeCommands(process.argv[2]);
33 changes: 33 additions & 0 deletions gems/wrapperV7_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# vim: set et sw=4 fenc=utf-8:
#
# wrapperV7_test.py

import subprocess

# Path to the Node.js wrapper script
JS_FILE_PATH = "wrapperV7.js"

def wrapper(input_data):
js_command = ["node", JS_FILE_PATH, input_data]
print("Input data sent to JavaScript:", input_data)

try:
# Run the command and capture the output and stderr
result = subprocess.run(js_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True)
print("Output from JavaScript:", result.stdout)
print("Errors from JavaScript:", result.stderr)
except subprocess.CalledProcessError as e:
print("Error running JavaScript script:", e)

# Strings to be passed as input_data
one = "init(33)"
two = "setRNG('something')"
three = 'share("AABB", 6, 3)'

# Concatenate the strings
input_data = ";".join([one, two, three])

# Call the wrapper function with input_data without quotes
wrapper(input_data)

0 comments on commit 6d15571

Please sign in to comment.