forked from meta-llama/codellama
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_script.js
More file actions
29 lines (20 loc) · 886 Bytes
/
Copy pathnode_script.js
File metadata and controls
29 lines (20 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const fs = require('fs');
// Define the named pipes
const PYTHON_TO_JS_PIPE = 'python_to_js_pipe';
const JS_TO_PYTHON_PIPE = 'js_to_python_pipe';
// Open pipes for reading and writing
const pythonToJsPipe = fs.openSync(PYTHON_TO_JS_PIPE, 'r');
const jsToPythonPipe = fs.openSync(JS_TO_PYTHON_PIPE, 'w');
// Read a message from Python
const messageFromPython = fs.readFileSync(pythonToJsPipe, 'utf-8').trim();
// Log the received message
console.log('Received message from Python:', messageFromPython);
// Process the message by appending to "Processed:"
const processedMessage = 'Processed: ' + messageFromPython;
// Log the message sent to Python
console.log('Sending message to Python:', processedMessage);
// Send the processed message back to Python
fs.writeSync(jsToPythonPipe, processedMessage);
// Close pipes
fs.closeSync(pythonToJsPipe);
fs.closeSync(jsToPythonPipe);