I have a dotnet core 3.1 web application that takes the file path and exe and runs it, but made the switch to dotnet core as want to make use of the cross platform capabilities.
Application is working on Windows based environments using Proocess.Start()
I've tried changing the extention of the environmental variable.
Windows code:
var process = await Task.Run(() =>
Process.Start($"{path}/{file}");
When running on a linux box I get System.ComponentModel.Win32Exception (8): Exec format error
if I change the file to .dll
extension from .exe
which won't run, I don't think Wine is an option.
How can I achieve this through C# or does it need to call a wrapper sript?
UPDATE
Both the exe and dll are built from a dotnet core application using the same 3.1, the code currently working with below:
var information = new ProcessStartInfo
{
UseShellExecute = false,
CreateNoWindow = true,
FileName = Path.Join(this.path, this.file),
};
var process = await Task.Run(() =>
Process.Start(information));
The error I get on my Linux box:
System.ComponentModel.Win32Exception (8): Exec format error at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
Exe file you have is likely Windows executable, and as such cannot be run on linux.
The .dll file you have is not an executable, so you cannot just start it via Process.Start
directly. It is however can be started (assuming it has entry point) via "dotnet" application, which should be in path on your linux server already if you have .NET core framework installed there. If not present in path - it's usually located at /usr/bin/dotnet. If .NET core is not installed - install it first. Then .dll can be run via:
dotnet PathToYour.dll
Your code then becomes:
var information = new ProcessStartInfo
{
UseShellExecute = false,
CreateNoWindow = true,
FileName = "dotnet",
Arguments = Path.Join(this.path, this.file)
};
If you have arguments to pass, then append them after dll path:
Arguments = Path.Join(this.path, this.file) + " " + "your arguments here"
Note that you can also run .dll the same way on windows, assuming .NET core framework is installed on target machine, because "dotnet.exe" is also present on windows and works the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With