I seem to have come across what may be a bug in mono, or that Im doing something wrong.
I use subprocesses to do things via C# however in some situations the terminal breaks by not showing what Im typing correctly. Ive managed to get this down to happening after using the Console to read a line.
Im currently on a Mac using mono version Mono JIT compiler version 3.10.0, but dont know if this is a mono thing or it can happen on Windows.
The minimum code I have been able to recreate the bug in is bellow:
using System;
using System.Diagnostics;
namespace Test
{
class MainClass
{
public static void Main( string[] args )
{
Console.ReadLine();
Process.Start("tee","text.txt").WaitForExit();
}
}
}
If you remove the read line, the output from tee will be printed after you input it (so you will see the same line twice) but with the read line it only displays the output from tee, not the input you type
IE:
Without the read line
~/test $ mcs program.cs && mono program.exe
this
this
is
is
writting
writting
to
to
file
file
^C
~/test $ cat text.txt
this
is
writting
to
file
And with the read line
~/test $ mcs program.cs && mono program.exe
readline
this
should
be
printing
as well
~/test $ cat text.txt
this
should
be
printing
as well
Related
This question already has answers here:
How to get csc.exe path?
(10 answers)
Closed 5 years ago.
I'm fairly new to C# and I'm trying to use cmd to compile a basic hello world file called test.cs. It contains the following:
// Similar to #include<foo.h> in C++, includes system namespaces in a program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// A name space declaration, a class is a group of namespaces
namespace Program1
{
class Hello // my class here, classes can contain multiple functions called methods which define it's behavior
{
static void Main(string[] args) // main method, just like in C/C++ it's the starting point for execution cycle
{
Console.WriteLine("Hello World");
Console.ReadKey(); // similar to _getch() in C++ waits for user to input something before closing
}
}
}
/*
* Other notes, .cs is a c# file extension
* cs files can be built via terminal by using csc foo.cs to generate foo.exe run it with foo
*/
When I try to run the line csc test.cs I get the following output:
Locate the path of csc.exe and add it your PATH environment variable.
In my case, the path for 64-bit C# compiler is C:\Windows\Microsoft.NET\Framework64\v4.0.30319.
Similarly, you can look for 32-bit C# compiler in C:\Windows\Microsoft.NET\Framework under different .NET framework version directories
There will be csc.exe for all versions like v2.0.XXXXX and v3.5. Select the one with the highest version in Framework64/Framework directory depending on your requirement.
Copy the path of csc.exe and add it to the PATH system environment variable.
Quit the cmd, and then launch again and run the program. That'd work.
I want to compile a simple "hello world" on mac console.
I have made dmcs symbolic on /usr/local/bin/.
using System;
class Hello
{
static void Main(){
 Console.WriteLine("Hello,World");
}
}
But after typing
dmcs Hello.cs
I get Hello.exe
.exe file seems a Windows file.
So, How to compile single c# file on mac console using mono?
JamesSugrue is right in your comment, you need to run the project using the mono framework using the described command line.
mono Hello.exe
The mono compiler creates files with extensions just like csc would on Windows. The difference is that on Mac and Linux the extension really is a suggestion about what is inside, rather than a rule like it is on Windows.
I have the following C# code
class Test
{
public static void Main(String[] argv)
{
Console.WriteLine("Hello ");
}
}
When I run the program from the command prompt, I do not see output. The c# file name is file.cs and compiles into file.exe.
When I run this from the command prompt:
c:\>file.exe
I do not see any output. But it works if I run this:
c:\>file.exe | more
I understand I need to do something other that console.WriteLine(). Is there any way that I can redirect all Console.WriteLine() calls to standard output?
Application type was set to Windows application in Visual Studio project properties.
I set the application type to "Console". This fixed the issue. Now all Console.WriteLine statements gets printed to command window.
I wrote a simple Hello World program in C# using Visual Studio 2013. I tried to compile it on the command line in Linux using:
mono --aot test.cs
However when I do that, I get the error:
Cannot open assembly 'test.cs': File does not contain a valid CIL image.
The file is just a typical C# console application using the default template that Visual Studio gives you.
You should use gmcs in order to compile your code, and mono to execute the interpreter, as one use javac and java commands.
You may reread the mono basics:
Let's say you have a C# file with the following code:
using System;
public class HelloWorld
{
static public void Main ()
{
Console.WriteLine ("Hello Mono World");
}
}
Compiling within the shell:
gmcs hello.cs
Executing it from the shell:
mono hello.exe
On my Windows 7 workstation, I have a variety of compilers installed - including MSVC9 and MSVC10. I recently noticed the following strange problem which only occurs in my MSVC10 environment.
In my MSVC9 shell (I use the one from the start menu), running csc.exe shows that it's using the C# 2008 compiler version 3.5.30729.4926 (.NET 3.5). In the MSVC10 shell, it's compiler version 4.0.30128.1. Now, the following little sample program builds with csc.exe as of MSVC9, but it fails with MSVC10:
using System;
using System.Windows.Automation;
namespace UIAutomationTest
{
class Program
{
static void Main()
{
}
}
}
I use the following command line (with MSVC9 as well as MSVC10) to build the program:
csc Hello.cs /r:UIAutomationClient.dll /nologo
With MSVC9, this succeeds (no output is printed and Hello.exe is built). With MSVC10, the build fails with this error message:
C:\src>csc Hello.cs /r:UIAutomationClient.dll /nologo
error CS0006: Metadata file 'UIAutomationClient.dll' could not be found
Does anybody know why that is?
UPDATE: I noticed that I can make the build work with MSVC10 if I modify the command line so that /r:UIAutomationClient.dll becomes /r:WPF\UIAutomationClient.dll.
Where is this UIAutomationClient.dll file located relative to your cs files?
Try passing the full path of UIAutomationClient.dll.