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.
Related
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.
My professor is asking me to submit my source code as my assignment in Visual Studio. I am working on a Windows Form application in C#, is my source code the actually code that I have been working on? Or is it like the background code that I don't edit or touch?
I'm only asking because my professor is completely useless when you need to ask her a question because she never replies in time and I need to submit my assignment in a few hours. I have searched the web for source code but I need a specific answer.
I don't want to read 50 pages just to find out the code I need to submit was the code I was working on. Thank you everyone for your help, I really do appreciate it.
The source code is the stuff you wrote in Visual Studio. Anything you need to actually build/compile the application is usually what we would call source code. You need to make sure your professor can also compile the application in Visual Studio just like you could, so send over any files that she would need to do that.
Right click on your solution file in visual studio, choose "Open the folder location". It will open the physical location of your files under the solution. Completely zip the contents in that path, submit it to him. Simple as that. You already knew it and we are making sure for you '-)
Source code is the raw code that you write when making an application or program. In short what your professor needs is your code.
Zip your solution folder which you find at
Documents => Visual Studio 2013/2015 => Projects => {name of your project}
This is the folder that you zip and send to your professor
Hope this helps.
SOURCE CODE ---> (COMPILER) ---> MACHINE CODE
SOURCE CODE :
Source code is any collection of computer instructions (possibly with comments) written using some human-readable computer language, usually as text. As a programmer you write source Code in your C# editor.
MACHINE CODE :
Machine Code is a set of instructions executed directly by a computer's central processing unit (CPU).
COMPILER :
A compiler is a computer program (or a set of programs) that transforms source code written in a programming language (C# in your case) into another computer language (the target language), with the latter often having a binary form known as Machine code.
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
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.
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.