There is exe developed in C# Windows. Run this on Linux.

patrick

Well-known member
Joined
Dec 5, 2021
Messages
251
Programming Experience
1-3
Hello.
I have a question.



The EXE file developed in C# will be executed on Linux.

The contents of the EXE developed in C# Windows are CSV file save to the specified path.
==>The contents of the EXE developed in C# Windows saves a CSV file in the specified path.

The path where the csv file is saved is string savepath = r“C:\folder” <=== The path on Linux will be entered into C# string as an argument.
C#:
using (StreamWriter wr = new StreamWriter(" r“C:\folder” "))
        {
            wr.WriteLine("#TYPE,MoveSpeed");
        }

is this possible?

Please Help me.
 
Let me start of by saying that you cannot take the .EXE that you compile on Windows, and just drop it on a *nix machine and expect it to run. You will need to re-compile the code on the target OS.

The next thing I will say is that is is really bad form to be creating a brand new folder at the root of someone's C: drive on Windows. Yes, that was the convention back in the Win3.1 days through Win9x, up to WinXP. After that the accepted convention is to use the OS recommended folders. So use one of the following to get the folder:
C#:
Environment.GetFolderPath(Environment.SpecialFolder.Personal))
or
C#:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))

With that out of the way, if your code was simply:
C#:
Console.Write("Enter path for the CSV file: ");
var savePath = Console.ReadLine();
using (var writer = new StreamWriter(savePath))
{
   writer.WriteLine("#TYPE,MoveSpeed");
}
Then the user can just enter the path that is appropriate for the OS on which the program is running on. Push the problem to the user.

If your path is sort of hard coded to store in the user's folder, then you could use use Path.Combine() to build up your savePath. Something like:
C#:
var dataPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal));
var savePath = Path.Combine(dataPath, "data.csv");
using (var writer = new StreamWriter(savePath))
{
   writer.WriteLine("#TYPE,MoveSpeed");
}
 
Last edited:
*** HUGE QUOTE REMOVED ***

Your Answer Thank you.

In Linux, StreamWriter (<== C# Function ) Does it work normally ?
 
Last edited by a moderator:
There is no need to quote the entire post above yours just to say "Thank you". If you have a specific question, just quote that part.

StreamWriter works normally as appropriate on that OS. You give it paths that are appropriate for that OS so that it can create or append to that file, and then by default it will write data to that file with the encodings and line separators appropriate for that OS. There is no magic conversion of a path for one OS being converted to another OS. The default encoding and line ending can be overridden.
 
Last edited:
Let me start of by saying that you cannot take the .EXE that you compile on Windows, and just drop it on a *nix machine and expect it to run
Actually, that's not quite accurate. I've no problems compiling net (core) apps on my windows machine, transferring the output to my raspberry Pi or Mac and launching it. The process is slightly different in that one doesn't run the .exe on the nix box but instead the .dll

On windows: MyProgram.exe
On *nix: dotnet MyProgram.dll

One has to be careful not to build windows-specific behavior in. For example, use Path.Combine to build paths, rather than concatening string together with "\", do not draw with GDI etc

-

It's also possible using the mono project to run framework apps in a similar way, without re compilation on the target machine. In those cases there is no DLL, one just runs "mono MyProgram.exe"
 
The process is slightly different in that one doesn't run the .exe on the nix box but instead the .dll

Which was my point.
 
Back
Top Bottom