I want to call a prolog program from C#. Is that possible?
I process the user input by c# and write into a file. I then want to call a prolog program which uses that file, then I want to show the content of the file to the user by c#.
Yes, if you don't want to link the two programs to a single binary but simply have one (C#) call the other (prolog) this can be done. And for any other language you can run on your computer too.
If you base your data exchange on files you need one file to send data from C#->prolog and perhaps a second one to return the result (prolog->C#)
You will find lots of examples to make C# call an external program here on SO (for example Launching an application (.EXE) from C#?)
If prolog does not allow you to pass the filename as parameter when you call it you will have to work with fixed filenames:
C# writes a request.txt
C# calls prolog program
Prolog reads request.txt and creates response.txt
Reading from files should be covered by the language, depending on the "dialect" even reading command line parameters should be.
If you use SWI-Prolog, you should google SWI-Prolog interface to C# and F#
Related
What I'm Trying to Achieve
I'm attempting to build a console game that has multiple console windows that would be displaying inventory, status effects, current map, and health. Another console would be the main one that gathers input to effect the other consoles. The reason I want to do it this way is so that the other consoles can be updating their "graphics" (or text) without disturbing the input flow.
What I've Tried So Far
So far, I've attempted to use System.IO's File, FileStream, StreamWriter, and StreamReader to communicate between the consoles via text files. The problem I've ran into is that, when the main console (the input console) is attempting to write inputs to a file--which is communicating with another console (the "graphics" console)--it throws an error because the "graphical" console is trying to read the input of the file (or vice versa).
I figured that making the FileStream's FileAccess be Readable would do the trick, but I ran into the same issue.
I think I could get this to work if I could communicate between the consoles to tell each other that one is done writing to or reading the file... kind of like a back and forth... "I'm writing to the file... okay, I'm done" "I'm reading the file... okay, I'm done" and the cycle continues...
So, in summary, I suppose, my question is how can I communicate between two consoles using files?
Possible Solutions I could try learning SQL, but I don't know if I'd end up running into the same issue... so, if I must learn SQL for this project, I suppose, that'd be my last option.
Thank you!
IPC (inter process communication) is the keyword you're looking for.
There are multiple ways to do IPC, e.g. shared memory, named pipes or similar. .NET has an IpcChannel which uses TCP or a named pipe if the destination is on the local PC.
I'm trying to work on an environment that its main function is to adopt Visual Programming to create NetLogo code (similar to Google's Blockly).
Right now, I'm using Unity3D to do the job and wondering if it's possible to access NetLogo from it. The objective is to send the generated code directly into the Code Tab, opening a blank project already with the code in the tab (without the user copying and pasting it there).
What I know up until now is that I can open NetLogo from Unity with a function called Process.Start, which takes 2 arguments: the first is the name of the target program to be executed ("NetLogo.exe"), the second one is a list of arguments that can be passed to the targeted program, which solely depends on each program, as found here and here. However, I didn't understand much about these arguments, which is why I recurred to ask.
Do I need to also work on a Java/Scala environment to do this for me with the Extensions API, or can I use these arguments in Process.Start to do it?
Thanks in advance.
You could create a fully formed .nlogo file (it's basically a text file with a specific format), and then launch NetLogo using your Process.start command with that filename as an argument so that NetLogo will open that specific file.
You could even create a .nlogo file as a template (with whatever interface items you want), and then use string search/replace to substitute in the code that you want in the code tab.
Alternatively, fancier things are possible with the Controlling API , but I don't know much about calling JVM code from within Unity, and I suspect that will be a bigger headache than you want... unless you really need a more tight-knit connection to NetLogo, or unless the performance overhead of starting a new NetLogo process each time is unacceptable.
I can find a lot of info on using C# as a scripting language (CSScript, Mono, Roslyn), but none of it seems to do what I need (or it does and I simply don't understand how to use it).
What I want to be able to do is this: Let's say I write a C# program with several classes. When the program starts it either looks for a cs file or a script in memory. I cut and paste one of the classes from the program either into the file or text box. When the program loads it finds that class and runs EXACTLY as it did before except now the class is in another location. I can edit this class (script) and access the other classes and variables in the program to change parts of the program without compiling.
Is this possible? If not, what is the best solution (cross platform would be good)?
I don't know what it is called but I want to be able to double click on my saved file and then my program should open and load the file. What is this called and how do I do it?
I am using c# wpf and .net 4.0
BR
How about the last 2 fields, what am I supposed to write there?
That is a file association, if you want this to happen on a client machine you need to register your application as the default application for a given extension. This question might be handy.
To actually handle the opening you need to process the arguments that are handed to your application, they will contain the file path. You can get the arguments either in the override of Application.OnStartup (e.Args) or Environment.GetCommandLineArgs.
you need to register the file extension and associate it to your program, either during the setup using certain APIs or from code when program executes the first time.
check these ones:
How to associate a file extension to the current executable in C#
Associate File Extension with Application
personally I do not like the 100% registry approach, there should be some Windows APIs for that and we should let those APIs to work without worrying about the Registry from our side, in my opinion.
I want to write a program is C# that will allow me to execute a vbscript step by step like I would do in a debugger. I know I can run vbscript by creating a new process class form System.Diagnostics but I was wondering if that will allow me to execute one line of vbs code at a time.
Background:We have this UI automation framework that generates vbscript based on the tests written in an excel file. This vbscript in turn make calls to a dll that performs actions on the application.
We want to get away from excel and put this automation framework in silverlight.
So what I need is an ability for the user to run though step by step through that vb script like a debugger on an interpreter would.
Any ideas?
You'd have to implement your own scripting host. Don't know much about it, ought to be challenging in C#. Start reading here.
You might try the MS ScriptControl.
You should be able to execute your code line by line, however maintaining the state might be a challenge depending on how many variables are being used by the VBScript or if you are just making one distinct call per line.