Execute interactive CLI appilcation from C/C++ [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Java has support for java.lang.Process. This can be used with java.lang.ProcessBuilder or Runtime.exec. With object of java.lang.Process. I can interactive with underlying application by reading output stream/error stream and writing to output stream.
Is there any way/library to do similar thing in either c or c++?
I try popen, but it is unidirectional, i.e. either I can write or read, can't do both.
Any suggestions are welcome. If there is not solution but have some work around, it also welcome.
Update: I am looking solution for Linux Platform.

There is no cross-platform way to launch a new process from either C or C++. Every platform will have its own interface to do so, assuming it has a concept of processes.
The two interfaces you're most likely to come across are the Windows CreateProcess and the POSIX fork/exec.
Since you mentioned reading/writing the subprocess's output/input, you'll also need to use the platform's pipe functions: CreatePipe on Windows or pipe on POSIX-compliant platforms.
There are cross-platform wrappers for all of that, such as Boost Process. None are included with the standard library though, so you'll have to build/install them as you would any other third-party library.

If you can use Managed C++ and .NET, you can use System.Diagnostics.Process, which does the same thing as with java.lang.Process.
Input Redirection
Output Redirection
The caveat is that you need to build your binary as a C++/CLI project, and have .NET as a dependency. You can get around this by putting the managed code in a separate utility library.

Related

Linux Deamon in C++ or Java? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I have a Windows service written by another developer who no longer works with me. It was written in C# with .NET 4.5 requirements. Our solution is making the move to Linux and the daemon naturally needs to be converted.
My dilemma is what to rewrite it in? C++ or Java? The daemon is not complicated. It's simply a controller for our other applications to ensure if they crash or are killed they are restarted. Aside from that it performs health checks through a named pipe and is controlled via a password protected web socket via a separate management Tomcat web interface and writes all of it to logs.
Please put aside any suggestions of "write in what you're most comfortable with" I have a fair amount of experience and knowledge in both languages, and I'll learn whatever else I need to as I go. My concern is the feasibility and effort to accomplish everything I need. I don't have any particular time constraints, but if one language is a fraction of the time of the other then maybe that's a better solution.
Writing it in Java looks like the easiest solution currently, but writing it in C++ has the advantage of being native no-frills code. However, I haven't ever written any web interface or socket code in C++ before, so I do not know the effort involved with that.
To break down my requirements:
Linux
Web interface for control
Named pipe for communicating with client applications
Existing code needs to be heavily refactored
Is C++ or Java more appropriate?
Edit: added more info
Edit2: I guess I should have mentioned that the code needs to be heavily refactored anyways. It was originally written in such a way that renders it difficult to make changes and additions. So rewriting is a cleaner solution at this point. As I mentioned, it's not a large program. Just a controller service.
Porting the solution to .Net Core may the way to go. It will run on Linux (and Mac for all intents and purposes...) and most of your codebase may need minimal refactoring. The only concern is if .Net Core currently has the features you would need supported in the app. And, .Net Core is still in preview.

How to run java code in HTML [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a piece of java code I would like to run in my web browser and publish online. How can I do this without using applets? I have tried java vertx but I am not sure how to use it and there are no good tutorials online.
The short answer is you can't. Browsers don't "speak" Java natively, which is why applets required a plugin. As you probably know, Google is in the process of removing support for the plugin technology used by the Java plugin (NPAPI) and so soon Java won't work in Chrome at all (it already doesn't under Linux).
Your only real options are:
Provide a means of running it server-side, like http://ideone.com and various other "online" compilers do.
Translate it from Java to JavaScript (either manually or using a tool), which the browser can then run. But note that Java and JavaScript are not only markedly different languages despite a superficial similarity in syntax, but the standard environment for each is also quite different from the other.
How you do either of those is much too broad a question for SO.

Passing data between C# and Java Apps [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have an API in C# .Net for uploading files whose size vary between 10 B - 100 KB. Per second, the system receives around 5 such calls. Now I want to pass this file to a JAVA process (Because it is a producer of Kafka, and we want it to be JVM based, while C# API is legacy). Both are going to reside on the same machine almost always. What is the best way of doing that?
I read about jni4net, IKVM for interacting with Java from C#. Would they be better or should I make it socket based (Web API in Java accepting the files), or should I read from the local filesystem where C# App has uploaded or any other option that I am missing?
In environment with high concurrency, reading from the local file-system might not be good idea.
You could use memory mapped files which java supports with FileChannel.
Depending on operating system, you could also use Named pipes for IPC, here is an article showing how to use pipes between .Net and Java:
http://v01ver-howto.blogspot.com/2010/04/howto-use-named-pipes-to-communicate.html
All options considered, i would go with sockets. They are portable and easy to do and will most likely meet performance requirements you have.
You may also use a message queue. You can either put a binary message, serialize the file or put the location of file on the queue if you are storing the files in the file system.
A solution with sockets and message queues will allow you to have a more distributed architecture i.e. not loading a single machine with too much work.
If you want to actually use the C# API from Java, a bridge is probably the way to go. It'll likely be more efficient than a Web API. Some bridges will also allow you to run the C# and the Java in the same process, which is more efficient still.
In addition to the bridges you mention, you might want to consider JNBridgePro. You can find more information at our website.
Disclosure -- I am affiliated with JNBridge.

interoperability java and c++ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
i want to write a program in two different languages java and c++ that needs a dynamic and interactive communication between its c++ component and java component.i know there is jni and jna for invoking native methods in java but i do not think this method is appropriate for my purpose.
for example : say a program that its User Interface is written in c++ and other in java, i do not think that communicating these two component can be done through jni and jna. for example Open Office is written in java and c++.
i searched the internet and find some method for Inter-process communication
like shared memory , pipe, signals, Message passing , ... but i don not know that Inter-process communication is what i need. it seems ipc is for communicating software in two different process but my program all is one process(am i right?!)
so my question is : how the programs that its component is written in different language communicate together? and how i can achieve this?
JNI has been exactly created for the purpose that you are describing; why exactly is it not "what you need"?
One other option: message brokers with implementations for different languages, like http://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol
But as you are stressing the latency, this might not be for your.

How to use other language libraries/frameworks with lua? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I really like Lua. It's like javascript without so many warts.
One thing I hate about Lua is the 3rd party support. Good luck finding any industrial-grade libraries or frameworks with Lua scripting - Unity 3d has javascript, but no Lua. Qt the same.
I'm wondering if there is a way to "bridge" an arbirtary Lua & some other application. Say, I want 2 programs running - Lua interpreter which handles all the fun stuff, and Java VM which recieves GUI information from Lua (and displays a Swing GUI) and sends user input to Lua.
EDIT: For clarification what I really really want.
From what I remember from CS101, every program has a standard input and output. Is it possible to have:
- Two programs running, 1st in the foreground (java VM), 2nd in background (lua interpreter). I mean, the 2nd one doesn't appear in the task bar. I'm not sure if that's possible, I'm no systems programmer :).
- Java stdin: gui description data + say, glCanvas or some other graphics data. Stdout: user input. Lua's stdin is joined with Java's stdout and vice versa.
I would thank for a code sample if possible.
EDIT: Nevermind, what I looked for was Inter Process Communication.
You can embed, for example, LuaJ in your Java app. Then you will be able to write any logic on Lua and some other things on Java.
Also, you can take a look on projects like kahlua and mochalua (both hosts on googlecode).

Categories

Resources