Running Java Application in C# NET - c#

I wrote an application a while ago in C# NET that basically allows the .exe I created to start/stop when the java application (Minecraft) starts and stops.
I would like to extend some more functionality to my application by basically allowing users to type commands into my console app, and in turn send these commands to the .jar file that is running.
I read something a while ago on stackoverflow that said there were some APIs that would basically let you manage Java apps inside of a C# NET app but I can't find it now.
Does anyone know how I could go about doing this?

If you launch and manage the java app from C# using the Process class, you can send input from your C# app to the launched java app process via Process.StandardInput.

Minecraft accepts commands from system in and responds to system out.
When you start minecraft from your application you basicly creates a new process. This process has two streams, one for system out and one for system in. You need to get hold of those streams. If you send characters to the system in stream, then they will be interpreted as commands to minecraft. If you read from the system out stream then you will get minecrafts response.
Your next task would be to let your users send commands to minecraft. One way to do this would be to let your users type in commands on a web page that you store in a file. You could have a separate thread read from the file and write the commands to minecraft's system in stream.

Related

Universal Windows Platform (UWP) C# app - How to run stand alone python inside your application

I am trying to find a way to call python from my UWP app. So far I have a .exe file that I have compiled from python using pyinstaller (www.pyinstaller.org/). This basically allows me to package up my python script as a standalone binary (ie: you don't need python to run it). This all works well and I can call my wrapped up python .exe via cmd.exe no problem:
$ process.exe -p "path\to\file"
$ Processing file: "path\to\file"...
$ Done.
So now I just need to call it from my UWP app - so I have added it to my application like so:
C# Project
Assets/process.exe
Frustratingly, I've not had much luck googling for answers to my problem - my attempted solutions so far have included:
Calling the "Assets/process.exe" directly from my app
Looked at "Launch an app and get results". I think this seams to be for external applications however... I certainly didn't get it going anyway.
Opening the cmd.exe (somehow) and calling my process.exe from there.
I'm not even sure if I'm trying to do this the correct way or not. Or if I have just not understood some of my findings. Or (fingers crossed) there is a simple solution to this I just don't know about and have somehow missed as I'm very new to UWP development and C#.
So any solutions/pointers here would be greatly appreciated thanks!!
UWP apps are 'sandboxed'; i.e. they have many security restrictions placed upon them to isolate them from the rest of Windows (like not being able to read/write to the Registry and not being able to directly access random files from the file system).
So there is no way to run an .exe (or any other executable) from your UWP app. If you have access to a StorageFile (say music, video or any other file format) then you can launch the file in the default program associated with that file type.

Multiple executable accessing the same folder at the same time

We have a python application that checks a directory(C:\sample\folder) every 5 seconds, there's also this external application(.net app) that puts file into that same directory (C:\sample\folder).
Will there be any conflict when the two application access the same folder at the same time (accidentally)?
Conflicts like :
the external app wont be able to place a file because the python app is currently walking through that same directory?
It should be fine for the external app to create and write to a file. If the Python app is reading a file, the .NET app may not be able to write to it while Python is reading it, without both processes opening the file in a shareable way, however.
Likewise if the Python app is going to start reading the newly-created file, it may either find that it can't do so until the .NET app has finished writing to it, or it may read incomplete data. Again, changes would quite possibly be required to both processes to allow reading at all.
It's worth thoroughly testing all the poosibilities you're concerned about, possibly involving the creation of a "fake" external app which writes to a file very slowly, but opening it in the same way that the real one does.

How to call an external windows application with UI by a c# application?

We have a program (A.exe) with GUI and a toolbar who does NLP stuff with some text.
In that toolbar we have function A which transform the text by adding some xml tags. Someone here (the boss) would like that I create a Web Service calling function A. It told me about Dynamic Data Exchange (he used it few years ago), I saw something like SendMessage.
The Web Service will be used by someone over the Internet : sending a text and getting the result as xml. The GUI program could not be started when someone calls the WS because it is too slow, so someone sugggests to launch this A.exe once for all and the WS will ask this A.exe by sending a DDE call. I don't know how A.exe will react in case of concurrent calls.
The Web Service will:
save the text file in a directory
call the A.exe
the A.exe will compute the text file and create the xml file
the WS will loop until the xml file exist
the WS will get the xml and send it as stream to the original caller
I would like to note that:
DDE is old and seems to need a DDE server capable program.
SendMessage is a little bit obscur as I am a Java developer.
I did not try named or anonymous pipes to make that call as suggested.
Thank you.
PS: It is an heresy to build a WS calling a server-side program with UI, isn't?
The answer to this question really depends on what you are trying to accomplish. Does your function alter data coming from an external data source such as a database or are you invoking a function within an application?
I would start with the following questions.
1) What does the function of the button do? Can it's functionality be moved into a service and shared between multiple applications?
2) Can you put the functionality inside a DLL and share between two applications?
3) Do the two apps really need to communicate with one another?
If the two processes MUST communicate with one another and you merely want application A to behave in response to a message from application B, consider using named pipes for TCP/IP communication. This is simple enough in .NET and provides quick communication between processes.
UPDATE: Here is a link with info on using named pipes: http://msdn.microsoft.com/en-us/library/bb546085.aspx.
UPDATE 2: This is an update after you updated your question. Do you have access to A.exe's source code? If you do, you have two options: 1) move that logic into your service or 2) modify A.exe to accept command-line parameters so that your service can invoke the process and get back results. If you don't have source code and you can't invoke A.exe from the command-line, then there isn't much you can do other than write the process yourself in a form your web service can call.
P.S. You don't have to worry about concurrent calls because each server request will execute a separate process.

windows automated task

i have c# program to save the path of the files and the password.
How can my program talk with backend program (ie 3rd application program) transparent to the user, to perform the tasks. And based on the data i captured using my c# progeam, given to use with that 3rd app program.
My C# program is just a frontend interface to automated the repeative task for keep manual operation from one source folder to destination folder to save operator time.
The problem is, i don't understand how to do this. I only know we need something like window automate task to get that done. How can i integrate my program + 3rd app.+window automate task, together?
thank you very much.
Create your program as a Windows Service, and make it run constantly
As for the data passing goes, you can output an XML file ( or write to a database), and let the 3 party app to use.
You may want to write a clearer question next time.

Ensuring Windows Mobile application is not running - From a desktop app

I have a windows mobile 5.0 application (smartphone) that contains a flat data file (CSV), which contains a header row (two doubles), and a list of entries (two doubles, DateTime, and a string).
Occasionally, I need to "sync" the mobile application with a desktop application. The desktop application should read the CSV from the mobile device, and replace it with a new CSV file, based on the contents of the old one.
This seems pretty easy via RAPI (I'm guessing), but I need to ensure that the mobile application is not running. Is there a way to do this?
Mutex? Remote Process Viewer like stuff? File locking?
Thanks for any help you have
Mike
Just use a simple file locking mechanism for the file being read/updated.
Either rename the file before use or create a second 'lock' file which you can check for the existence of.
For whatever reason, the built-in RAPI Functions don't have anything for checking running processes like the ToolHelp API's. With C you could create a set of custom functions in a device library that call the ToolHelp APIs and in turn are called through CeRapiInvoke (which is a generic catch-all entry point for custom RAPI functions). Unfortunately there's no simple mechanism to do this in managed code.
Just thought of an easy way.
Every 3 seconds the program is running, update a registry key with the current datetime.
When I want to sync, check the mobile registry, check it again 5 seconds later. If the values changed, the program is still running.

Categories