I'm trying to make a vb.net application that has got 2 textboxes, 7 radio buttons and 2 buttons(one named compile and the other 'run'). How can I load the content of a C/C++(or any programming language) file into the 1st textbox and on clicking the compile button, i should be able to show the errors or the C/C++ program in the 2nd textbox. On clicking Run, I should be able to show the output in the 2nd textbox. In short, I want to use the 2nd textbox as a terminal/console. The radio buttons are 4 selecting the language C or C++ or python or C# or java or perl or vb.
Are the compilers of all these languages present in .net? If so how can I call them?
Look at the System.IO namespace for clues as to how you go about loading the contents of a file into a text box. In particular, the File class.
System.IO.File Class
Look at the System.Diagnostics namespace for clues as to how to go about launching a process and capturing the output. In particular, the Process class.
System.Diagnostics.Process Class
This SO page...
Capturing the Console Output in .NET (C#)
... will give you some more info around capturing console output.
Compiling can be done by calling cl.exe which comes with Visual Studio. Of course you could also use GCC instead.
Related
I want to right-click on a text file and "Open With..." it with my own program, but I can't find any information on how to do that. I want to make my program in C++ or with WinForms (C#).
I want to open that file and to use my program as an interpreter on a small "homemade programming language", so I want to pass the data from the file directly to my program.
Can anyone help me?
*hope I'm clear enough on what I'm trying to do.
I'm just gonna to answer your Question for C#. If you still need C++ support you can tell me.
Option 1 - Drop down:
So if you for example create a Console-Application in C# (Visual Studio), it will look like this:
As you can see in the Picture: the Program accepts Arguments (args String Array)
If you drag & drop your file on your .exe, the filepath of the file you dropped will be saved in the args String Array. Now you can read the file (for example with the File-Class).
Option 2 - Right Click -> Open with my Program:
For that, you can simply add a new entry in HKEY_CLASSES_ROOT\Directory\Background\shell (Windows Registry) to register you Program as a "Right Click Menu Program".
Here is a detailed How-To:
https://www.howtogeek.com/howto/windows-vista/add-any-application-to-the-desktop-right-click-menu-in-vista/
After you added your Program to the Windows Registry you can proceed as shown in Option 1 (args).
Any more questions? Let me know.
Greets
Bennet
EDIT:
Sorry, didnt really read the comments :D but i guess your Question is answered. I will let this stay here for future readers which dont read the comments either ;)
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 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#
I am new to ASP.NET and I have a challenge here:
I have to create a webpage which should take C/C++ program from textarea and should produce output of the program below the textarea using label when a button is clicked on the webpage.
I have no difficulty creating the front page(textarea,button,label or other controls) and reading the content of textarea in back end page(cs page).
But I don't have any idea how I can compile and run the program read from textarea and produce the output which can be assigned to a label on webpage.
Any help on this will be much appreciated.
Thanks
You can use
System.Diagnostics.Process.Start()
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx
followed by
Process.WaitForExit
to run the Visual C++ compiler (CL.EXE). The documentation for CL.EXE is here: http://msdn.microsoft.com/en-us/library/610ecb4h.aspx
Your needs might be as simple as:
c:\path-to-compiler\cl.exe file.cpp /clr
In particular, I'd recommend that you review all your choices for the /clr option: http://msdn.microsoft.com/en-us/library/k8d11d4s(v=VS.80).aspx
You need to have Visual C++ on your machine.
I assume you only want to treat single source file programs using only standard libraries. I also assume that you are working on Windows (asp.net). As soon as you have program source text, you can save it to a file. Then you start cl as an external program with your source as parameter to compile it. And finally you start the program you have just compiled. Of course, you will have to give pipes for Stdout and probably stdin and stderr.
What I am trying to do is see if I can use the MinGW C++ compiler and debugger to compile files using a C# app. I want to be able to read the output and write to the input (input mainly for the debugger) within the C# app whenever I need to.
Reading from output will be much like Visual Studio does in its 'Output' window durring a project build.
I have used System.Diagnostics.Process before but haven't been able to figure out how to interact with the processes.
So, how do I take control of std input/output?
Redirecting standard input
Reading standard output
The following question shows how to capture standard output:
How do I run a Console Application, capture the output and display it in a Literal?
Writing to standard input is similar -- set RedirectStandardInput to true, and use a streamwriter to write to it:
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardinput.aspx