Comments (10)
Neutralinojs allows communication with the parent process using standard input (stdin) and standard output (stdout). This can be useful for exchanging data and commands between Neutralinojs applications and their parent processes.
Receiving Data from Parent Process (stdin):
const { stdin } = require('@neutralinojs/neu');
stdin.on('data', (data) => {
console.log(Received data from parent process: ${data}
);
// Process the received data as needed
});
Sending Data to Parent Process (stdout):
const { stdout } = require('@neutralinojs/neu');
// Send data to the parent process
stdout.write('Data to send to the parent process\n');
Bidirectional Communication:
const { stdin, stdout } = require('@neutralinojs/neu');
// Listen for data from the parent process
stdin.on('data', (data) => {
console.log(Received data from parent process: ${data}
);
// Process the received data and send a response
const response = `Processed: ${data}`;
stdout.write(response);
});
from neutralinojs.
Hello, thanks for your explanation. Currently, there is no official API to read the main process's stdin, but we can add a new function like app.readStdIn(untilEof=true/false)
(or in filesystem
) and a new event processStdIn
in the next release (Feel free to add your suggestions for the function). I'll add this issue as a feature request.
I think some alternative methods with the current release are:
- Writing a custom API function by editing the source.
- Using CLI arguments to pass a file input, read it using Neutralino APIs, write it to a file, and read it using
cat
.
Thanks for posting this feature request 🎉
from neutralinojs.
Cool! I'll give it a try.
from neutralinojs.
Hello @Hill-98, do you need to communicate with the Neutralinojs framework process? For that, you can use the framework's WebSocket connection. If you need to communicate with a child process, you can use the os.spawnProcess
function.
from neutralinojs.
@shalithasuranga Thanks for your reply, but it's neither of those, I need to communicate with the parent process.
like this:
cat some.txt | neutralinojs-program | grep some
Can I handle stdin and stdout?
from neutralinojs.
good one
from neutralinojs.
To send data from Neutralino to the parent process, you can write to the stdout stream. Here's an example in JavaScript:
// Send data to the parent process
function sendDataToParent(data) {
console.log(JSON.stringify(data));
}
In this example, JSON.stringify(data) converts the data into a JSON string, and console.log writes it to the stdout stream. You can call this function whenever you want to send data to the parent process.
To receive data in Neutralino from the parent process, you can read from the stdin stream. Here's an example:
// Read data from stdin
process.stdin.on('data', (data) => {
const receivedData = JSON.parse(data);
handleReceivedData(receivedData);
});
// Handle the received data
function handleReceivedData(data) {
// Process the received data
console.log('Received data from parent process:', data);
}
In this example, the process.stdin.on event listener is used to listen for data on the stdin stream. When data is received, it is parsed using JSON.parse to convert it from a JSON string to a JavaScript object. You can then handle the received data in the handleReceivedData function.
Hope this helps.
from neutralinojs.
Hello everyone, now we have added readProcessInput(readAll=true/false), writeProcessOutput(), and writeProcessError()
functions. We'll release them with the next framework version soon. Thanks for reporting and discussing this 🎉
Example (testable by tomorrow with nightly
):
await Neutralino.app.writeProcessOutput('Enter your name: ');
let name = await Neutralino.app.readProcessInput();
await Neutralino.app.writeProcessOutput(`Hello ${name}...`);
from neutralinojs.
@shalithasuranga Are these implemented correctly only on Linux?
I found that Windows didn't work. It seems to be because the Windows version works in "Window mode" instead of "Console mode". As far as I understand, one Windows program cannot implement both modes at the same time, so is it possible to provide another binary for Windows separately? (Like: neutralino-win_x64_console.exe
)
from neutralinojs.
Hey @Hill-98, thanks for posting this info. Mm. yeah, according to internet documentations, I also found the same thing you've mentioned about Windows executables. The issue is that I couldn't test this feature on Windows since our Azure sponsorship was terminated. Looks like we need to get some help from a contributor until I re-apply for the Azure sponsorship. Thanks 🎉
from neutralinojs.
Related Issues (20)
- demo
- Windows Crash if User Directory has Special Character HOT 2
- Bug in upcoming Extension binding? HOT 4
- neu update should update the neutralino.js file as well
- issue with neu create
- NL_PATH doesn't get translation of a Windows system folder HOT 2
- borderless windows on mac have multiple issues HOT 2
- Compatibility with SvelteKit HOT 1
- Implement `window.transparent` configuration option for Windows HOT 10
- Remove unused code from the webview.h file
- WebSocket Server with binary mode support HOT 1
- ReactJS Hot-Reload refreshes the whole page HOT 2
- `neu run` does not remove its tray icon upon exiting HOT 5
- `setDraggableRegion` doesn't work sometimes HOT 3
- Neutralino.storage don't work when the app is launched in a directory path with special characters on Windows
- Execute a shell command and emit events triggered by stdOut HOT 3
- `Neutralino.storage` functions – promises always pending HOT 1
- neu: ERRR Unable to dispatch event to the app
- `Open with → Choose another app` function not working HOT 5
- Faster startup HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from neutralinojs.