Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running `mklink` in ProcessStartInfo

I am working on a c# program that needs to be compatible with Windows and Linux (Mono).

I am trying to create a symbolic link in both platforms and I am using ProcessStartInfo in order for this to work. I haven't tried this on Linux yet but on Windows I am using the following code

ProcessStartInfo process = new ProcessStartInfo();

                    process.CreateNoWindow = true;
                    process.UseShellExecute = false;
                    process.FileName = "mklink";
                    process.WindowStyle = ProcessWindowStyle.Hidden;
                    process.Arguments = "/D " + webFolder + "MyFolder" + webFolder + "MyFolder_" + version;
                    Process.Start(process);

When I run the above code I get

System.ComponentModel.Win32Exception: The system cannot find the file specified

If I run mklink in command prompt it works fine.

I've had a look on Google and it says about doing a [DllImport("kernel32.dll")] but this isn't going to work on Linux.

Thanks for any help you can provide.

like image 820
Boardy Avatar asked Jul 08 '12 19:07

Boardy


1 Answers

mklink is a command of the cmd.exe program, not a stand-alone program.

To run mklink, you have to actually invoke cmd.exe with an appropriate set of parameters, like this:

ProcessInfo = new ProcessStartInfo("cmd.exe", "/c mklink " + argumentsForMklink);
like image 140
Eric J. Avatar answered Oct 12 '22 05:10

Eric J.