New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to pass stdio to nodejs #163
Comments
I add this question in SO |
@Taritsyn Did you have any idea? |
related to Taritsyn/JavaScriptEngineSwitcher#110 |
@JeremyTCD Did you have any Idea? or if this library does not support this, Did you have any advice to how to add this feature? maybe I can provide PR for this |
Hey apologies for the slow response, I'm not sure how to pipe output when using JavaScriptEngineSwitcher, but if you use this library directly, you can do it like this: using Jering.Javascript.NodeJS;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Example.Logging
{
internal class Program
{
static async Task Main(string[] _)
{
// Prepare DI services
var serviceCollection = new ServiceCollection();
serviceCollection.AddNodeJS();
serviceCollection.AddLogging((ILoggingBuilder loggingBuilder) =>
{
loggingBuilder.AddConsole();
});
// Get INodeJSService
IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();
INodeJSService nodeJSService = serviceProvider.GetRequiredService<INodeJSService>();
// Invoke js
await nodeJSService.InvokeFromStringAsync(@"module.exports = (callback) => {
console.log('Hello world!');
callback(null);
}").ConfigureAwait(false);
}
}
} Your project will have to reference the You will get output like:
You can filter output by following Microsoft's instructions here. Let me know if you have any issues. |
@JeremyTCD are you sure, this method, redirect standard I/O to/from NodeJS, for example, what is happen, if I run below code in the NodeJS const stdin = process.openStdin()
process.stdout.write('Enter name: ')
stdin.addListener('data', text => {
const name = text.toString().trim()
console.log('Your name is: ' + name)
stdin.pause() // stop reading
}) Are you sure, nodeJs get input from my standard input? thanks |
Ah it does not. I assumed from your "hi" example that you just needed output, stdin is not piped from .Net to Node.js. Would an invocation work? E.g. string? data = Console.ReadLine();
nodeJSService.InvokeFromStringAsync(..., args: new object?[] { data }); |
@JeremyTCD No, I want to bind (redirect) all input and output together, from/to .Net Node.js. for example, I have console application in Node.JS and I want when run this app in .Net, user can seamless using this app. thanks |
Options:
|
I do not understand, did you can provide some example? (If I understand correctly, you says Jering can support redirection both standard output and input? correct?) |
Piping input to Node.js processes is not supported out-of-the-box. But there are ways to implement such behaviour. For the first option, read input and pass it to the Node.js process using invocations, like in this comment. As for the second option, replace the |
ITNOA
I want to link my stdio from C# Console Application to NodeJs, to better describe my question, I create a sample like below
I have some code like below
and my
SpawnServer.js
is like belowI like to see
Hi
in my C# Console Application, But I do not know, How to do it?Note: All code is in https://github.com/soroshsabz/visualstudio-ansible/tree/features/4-support-ansible-language-server
thanks
The text was updated successfully, but these errors were encountered: