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.
Popen attempts, functional but NOT usable
- Loading branch information
Showing
3 changed files
with
108 additions
and
18 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,43 @@ | ||
#! /usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# vim: set et sw=4 fenc=utf-8: | ||
# | ||
# proc_commV1.py | ||
|
||
# Trying to use process.communicate() with Node | ||
|
||
import subprocess | ||
|
||
#JS_FILE_PATH = "wrapperV7.js" | ||
#js_command = ["node", "-i", JS_FILE_PATH] | ||
|
||
# Start the Node.js process | ||
node_process = subprocess.Popen(["node", "-i"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) | ||
|
||
# Send JavaScript commands | ||
commands = [ | ||
"const secrets = require('../secrets.js/secrets.js')", | ||
"console.log('Hello from Node.js!')", | ||
"console.log(2 + 2)", | ||
"console.log(Math.random())", | ||
"var HHGTTG = 42", | ||
"console.log(HHGTTG)", | ||
"secrets.share('1234abc', 6, 3)" | ||
] | ||
|
||
|
||
# Send commands to the Node.js process | ||
for command in commands: | ||
node_process.stdin.write(command + '\n') | ||
|
||
# Read output | ||
output, error = node_process.communicate() | ||
|
||
# Close stdin to indicate end of input | ||
node_process.stdin.close() | ||
|
||
print("Output:") | ||
print(output) | ||
|
||
print("Error:") | ||
print(error) |
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,47 @@ | ||
#! /usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# vim: set et sw=4 fenc=utf-8: | ||
# | ||
# proc_commV2.py | ||
|
||
# Trying to use process.communicate() with Node | ||
|
||
import subprocess | ||
|
||
#JS_FILE_PATH = "wrapperV7.js" | ||
#js_command = ["node", "-i", JS_FILE_PATH] | ||
|
||
# Start the Node.js process | ||
node_process = subprocess.Popen(["node", "-i"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) | ||
|
||
# Send JavaScript commands | ||
commands = [ | ||
"const secrets = require('../secrets.js/secrets.js')", | ||
"console.log('Hello from Node.js!')", | ||
"console.log(2 + 2)", | ||
"console.log(Math.random())", | ||
"var HHGTTG = 42", | ||
"console.log(HHGTTG)", | ||
"secrets.share('1234abc', 6, 3)" | ||
] | ||
|
||
#print(commands[0]) | ||
|
||
# Send commands to the Node.js process | ||
for command in commands: | ||
node_process.stdin.write(command + '\n') | ||
#node_process.stdin.write(commands[1] + '\n') | ||
#foo.stdout.readline() | ||
|
||
# Read output | ||
output, error = node_process.communicate() | ||
|
||
# Close stdin to indicate end of input | ||
node_process.stdin.close() | ||
|
||
|
||
print("Output:") | ||
print(output) | ||
|
||
print("Error:") | ||
print(error) |
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 |
---|---|---|
@@ -1,21 +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]); | ||
// | ||
// // 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]); |