generated from rochacbruno/python-project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
2 changed files
with
54 additions
and
0 deletions.
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,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]); |
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,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) |